STINNER Victor <victor.stin...@haypocalc.com> added the comment:

I don't like the idea of adding new fields to os.stat() *by default* because it 
may break backward compatibility. And if the new fields are decimal.Decimal 
objects, the module has to be imported and it means that any call to os.stat() 
would be slower just to provide timestamps with a finer resolution: this is not 
acceptable if you just want to check if a file exists.

In the issue #13882, I propose to add a format argument to functions getting 
time (time.time(), time.clock(), etc.). My patch doesn't change the default 
type, but add a "decimal" format to get time as a decimal.Decimal object.

The option (format) value is a string to be able to add other formats without 
having to change the API later:

 - "decimal": decimal.Decimal object
 - "datetime": datetime.datetime object
 - "tuple": low-level value, (intpart: int, floatpart: int, divisor: int)
 - "float128"
 - etc.

For os.stat(), the optional argument can be called "timestamp".

So if you want timestamps in the best available resolution, use 
timestamp="decimal". If you prefer the datetime API, use timestamp="datetime". 
If you don't care of timestamps, just call os.stat() without setting the 
timestamp option ;-)

We might add a registry to add user-defined types, but the "tuple" format 
should be enough. (I don't know if we need to expose the low level "tuple" 
format.)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11457>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to