On Mon, Aug 17, 2015 at 12:44 PM, Chris Barker <[email protected]> wrote: > I _think_ I recall form this discussion that this was done, rather than an > error, because it was decided that such calls should never raise an > exception (also, the replace() functionality makes it all too likely). So > it's probably best to do it in the proposed way, but the PEP should make it > clear that a prime motivation is to avoid Exceptions in such code.
There are many reasons why the proposed behavior is a good one, but raising an exception from .timestamp() is not really a contender. We cannot make currently valid programs crash and there are many ways a missing time can be produced by a valid program even without an explicit .replace() call. For example, adding timedelta(1) to a valid datetime can produce a missing datetime. It is also common in some algorithms to reattach tzinfo without checking the other datetime components. For example, stdlib's own datetime.tzinfo.fromutc() does that. I am going to add an explanation of how to implement code that rejects missing values to the PEP and this will probably address your concern. (The code is just if dt.replace(first=True).timestamp() > dt.replace(first=False).timestamp(): raise MissingTimeError.) _______________________________________________ Datetime-SIG mailing list [email protected] https://mail.python.org/mailman/listinfo/datetime-sig The PSF Code of Conduct applies to this mailing list: https://www.python.org/psf/codeofconduct/
