[Python-ideas] PEP: Extended stat_result (First Draft)

Pieter Nagel pieter at nagel.co.za
Mon May 6 15:11:37 CEST 2013


On Mon, 2013-05-06 at 14:50 +0200, Christian Heimes wrote:
> Am 06.05.2013 10:30, schrieb Pieter Nagel:
> > Abstract
> > ========
> > 
> > This PEP proposes extending the result of ``os.stat()``, ``os.fstat()`` and
> > ``os.lstat()`` calls with added methods such as ``is_file()``.  These added
> > methods will obviate the need to use the ``stat`` module to interpret the
> > result of these calls.
> 
> A side note:
> 
> The stat module has a flaw. It's a pure Python module with hard coded
> constants. So far this has worked on all known platforms because the
> platforms are all using the same constants with equal meaning. AFAIK the
> POSIX specs only specify the names of the constants but not any values.

In theory my PEP provides a mechanism for abstracting away the precise
bit values of the stat flags.

The only wrinkle is that I currently specify the new is_xxx() methods'
behaviour in terms of the current hard coded constants in stat.

To decouple my PEP from the precise values of the ST_ constants, I'll
have to find a way to formulate the behaviour of is_file() etc. on
stat_result, and make it clear that it is most likely the same as
stat.S_ISREG() on current platforms, without tying myself to the current
values of stat.S_ISREG.


I'll think on it.


-- 
Pieter Nagel





More information about the Python-ideas mailing list