~sschwarzer/ftputil#91: 
use namedtuple for stat result.

The information returned by stat is not intuitive:

(33152, None, None, 1, u'1004', u'1004', 6, None, 1421830200.0, None)

I know where to get the relevant docs. But it would be much easier to deal with the result, if a namedtuple would be used.

Status
RESOLVED FIXED
Submitter
ftputiluser (unverified)
Assigned to
No-one
Submitted
9 years ago
Updated
9 years ago
Labels
enhancement library

schwa (unverified) 8 years ago · edit

I just gave it a try:

Before:

class StatResult(tuple):
    """
    Support class resembling a tuple like that returned from
    `os.(l)stat`.
    """
    ...

After:

StatResultBase = collections.namedtuple(
                   "StatResult", ["st_mode", "st_ino", "st_dev", "st_nlink",
                                  "st_uid", "st_gid", "st_size", "st_atime",
                                  "st_mtime", "st_ctime"])


class StatResult(StatResultBase):
    """
    Support class resembling a tuple like that returned from
    `os.(l)stat`.
    """
    ...

The problem is that before the StatResult constructor took one argument (the tuple with the items to use) and with the change the StatResult constructor takes 11 arguments (the tuple items).

Since StatResult is a public class for implementation of custom parsers, I don't want to change the StatResult constructor.

schwa (unverified) 8 years ago · edit

As you suggest, I also think the idea behind using a namedtuple isn't the class itself, but the representation of its instances. Therefore I added a repr to StatResult so that the representation looks like that of a namedtuple [236781615dd35adca1dbed54f2393196fbd14523](https://git.sr.ht/~sschwarzer/ftputil/commit/236781615dd35adca1dbed54f2393196fbd14523 "Add __repr__ so that a StatResult looks like a named tuple (#91) ...").

Register here or Log in to comment, or comment via email.