[Datetime-SIG] pytz vs. PEP 495 Was: PEP-431/495

Ethan Furman ethan at stoneleaf.us
Mon Aug 24 21:54:03 CEST 2015


On 08/24/2015 12:14 PM, Alexander Belopolsky wrote:
> On Mon, Aug 24, 2015 at 3:05 PM, Ethan Furman wrote:

>> I would be much happier about this if:
>>
>> >>> datetime(2004, 4, 4, 2, first=None, tzinfo=Eastern2).astimezone().isoformat()
>> Traceback (most recent call last):
>         File "<stdin>", line 1, in <module>
>         File ".../pytz/tzinfo.py", line 327, in localize
>           raise NonExistentTimeError(dt)
>       NonExistentTimeError: 2004-04-04 02:00:00
>
>     Giving the programmer an easier option to use if they want an exception.
>
>
> Which of the steps you want to raise an exception:
>
> >>> dt = datetime(2004, 4, 4, 2, first=None, tzinfo=Eastern2)

This one.

> and why?

Because Python shouldn't be guessing.  'datetime' doesn't know how the programmer got those numbers, and so can't know whether subtraction was used and 1am is the right answer, or addition was used 
and 3am is the right answer.

> The stack trace that you presented comes for "localize", but no such method
>  is proposed in PEP 495.

Sorry, I copied the stack trace with only slight modification -- the import part is the NonExistantTimeError (or AmbiguousTimeError for the opposite scenario).

--
~Ethan~


More information about the Datetime-SIG mailing list