[Python-Dev] PEP 471 (scandir): Add a new DirEntry.inode() method?

Gregory P. Smith greg at krypto.org
Sat Feb 14 18:47:19 CET 2015


On Sat Feb 14 2015 at 3:17:51 AM Victor Stinner <victor.stinner at gmail.com>
wrote:

> 2015-02-14 11:57 GMT+01:00 Victor Stinner <victor.stinner at gmail.com>:
> > I propose something else: a DirEntry.inode read-only property (...)
>
> Full DirEntry API:
>
> - name (str) attribute
> - path (str) read-only property, created at the first call
> - inode (int or None) attribute <=== my proposition
>

+1 we need to provide the inode (we shouldn't be throwing anything from the
underlying directory entry away when possible). But...

I think the "or None" semantics are a bad idea.  It'd be better for this to
raise AttributeError on Windows so that someone can't write the most
natural form of code assuming that inode is valid and have it appear to
work on Windows when in fact it'd do the wrong thing.


> - is_dir(*, follow_symlinks=True)
> - is_file(*, follow_symlinks=True)
> - is_symlink(*, follow_symlinks=True)
> - stat(*, follow_symlinks=True)
>
> is_dir(), is_file(), is_symlink() and stat() are method because they
> may all require a syscall (os.stat or os.lstat). They all cache their
> result. In some cases, the result is already known when DirEntry is
> created. In most cases, a single call to os.stat() is required to fill
> the result of all methods.
>
> Victor
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> greg%40krypto.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150214/58ddef61/attachment.html>


More information about the Python-Dev mailing list