[Python-Dev] Store timestamps as decimal.Decimal objects
victor.stinner at haypocalc.com
Tue Jan 31 13:20:23 CET 2012
> - use datetime (bad idea for the reasons Martin mentioned)
It is only a bad idea if it is the only available choice.
> - use timedelta (not mentioned on the tracker, but a *much* better fit
> for a timestamp than datetime, since timestamps are relative to the
> epoch while datetime objects try to be absolute)
Last version of my patch supports also timedelta.
> - a survey of what other languages are doing to cope with nanosecond
> time resolutions (as suggested by Raymond but not actually done as far
> I could see on the tracker)
I didn't check that right now. I don't know if it is really revelant
because some languages don't have a builtin Decimal class or no
"builtin" datetime module.
> - how to avoid a negative performance impact on os.stat() (new API?
> flag argument? new lazily populated attributes accessed by name only?)
Because timestamp is an optional argument to os.stat() and the
behaviour is unchanged by default, the performance impact of my patch
on os.stat() is null (if you don't set timestamp argument).
> Having a low-level module like os needing to know about higher-level
> types like decimal.Decimal and datetime.datetime (or even timedelta)
> should be setting off all kinds of warning bells.
What is the problem of using decimal in the os module? Especially if
it is an option.
In my patch version 6, the timestamp argument is now a type (e.g.
decimal.Decimal) instead of a string, so the os module doesn't import
directly the module (well, to be exact, it does import the module, but
the module should already be in the cache, sys.modules).
> You're right that supporting this does mean being able to at least
> select between 'int', 'float' and <high precision> output, but that's
> the kind of case that can be made most clearly in a PEP.
Why do you want to limit the available formats? Why not giving the
choice to the user between Decimal, datetime and timedelta? Each type
has a different use case and different features, sometimes exclusive.
More information about the Python-Dev