Re: [Datetime-SIG] PEP-495 - Strict Invalid Time Checking
On 08/25/2015 02:22 PM, Alexander Belopolsky wrote:
On Tue, Aug 25, 2015 at 5:04 PM, Carl Meyer wrote:
I can't imagine how raising an exception on invalid times only if a non-default sentinel value is given for a flag that is _new in PEP 495_ could possibly break 4000 lines of existing datetime tests.
OK, so datetime module itself will never set fold=-1. In the list below, can you mark the methods that need to be patched to check the fold attribute in your preferred design:
If `fold=None` is present /when attempting to create a datetime/ that is ambiguous or invalid, an exception is raised /at that moment/ meaning that a datetime with `fold=None` /will never exist/. `fold=None` /will not be the default/.
datetime.__add__ no datetime.__eq__ no datetime.__format__ no datetime.__ge__ no datetime.__gt__ no datetime.__hash__ no datetime.__le__ no datetime.__lt__ no datetime.__ne__ no datetime.__new__ YES datetime.__radd__ no datetime.__reduce__ no datetime.__reduce_ex__ no datetime.__repr__ no datetime.__rsub__ no datetime.__str__ no datetime.astimezone no datetime.combine YES (could have a time instance with fold=None) datetime.ctime no datetime.date no datetime.dst no datetime.fromordinal no datetime.fromtimestamp no datetime.isocalendar no datetime.isoformat no datetime.isoweekday no datetime.now no datetime.replace YES datetime.strftime no datetime.strptime only if `fold=` is allowed datetime.time no datetime.timestamp no datetime.timetuple no datetime.timetz no datetime.today no datetime.toordinal no datetime.tzname no datetime.utcfromtimestamp no datetime.utcnow no datetime.utcoffset no datetime.utctimetuple no datetime.weekday no
-- ~Ethan~
On Thu, Aug 27, 2015 at 8:13 AM, Ethan Furman <ethan@stoneleaf.us> wrote: [Alexander Belopolsky]
OK, so datetime module itself will never set fold=-1. In the list
below, can you mark the methods that need to be patched to check the fold attribute in your preferred design:
[Ethan Furman] datetime.__new__ YES datetime.combine YES (could have a time instance with fold=None) datetime.replace YES datetime.strptime only if `fold=` is allowed [Ethan Furman]
If `fold=None` is present /when attempting to create a datetime/ that is
ambiguous or invalid, an exception is raised /at that moment/ meaning that a datetime with `fold=None` /will never exist/. fold=None` /will not be the default/. I don't grasp the significance of the slashes in your text above, but it looks like your idea is similar to the one I outlined in the "Strict Invalid Time Checking: an idea for another PEP" thread. As I said there, it is workable, but there are many details that need to be thought out before this idea becomes PEP-worthy. Let's move the discussion of those details to a thread that does not have PEP 495 in the subject. Feel free to reuse my thread or open a new one. What we can do in PEP 495 is tighten the language about acceptable values for the fold= argument in replace(). Since pure python implementation currently allows None for year through microsecond arguments, we have the following text in the PEP: """ In CPython, any non-integer value of fold [passed to replace()] will raise a TypeError , but other implementations may allow the value None to behave the same as when fold is not given. """ I am fine with removing this text and leaving fold=None option open for the future PEPs to explore.
participants (2)
-
Alexander Belopolsky
-
Ethan Furman