Opened 7 years ago

Closed 6 years ago

#27138 closed Bug (fixed)

timezone.localtime accepts naive datetimes on Python ≥ 3.6

Reported by: Aymeric Augustin Owned by: Joachim Jablon
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: joachim@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


timezone.localtime is documented not to accept naive datetimes, however, it does on Python ≥ 3.6, cf. a7a7ecd2b026c61a39a46d2d7eced0e06a92c970.

For the sake of consistency across Python versions, I think it would be best to implement one of the following two options:

  1. maintain the current API, check for naive datetimes and raise an exception,
  2. accept naive datetimes, convert them to aware datetimes with a warning (like Django does in other places) and update the documentation accordingly.

See for a longer discussion of option 2.

Change History (5)

comment:1 Changed 7 years ago by Aymeric Augustin

Component: UncategorizedUtilities
Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Joachim Jablon

Owner: changed from nobody to Joachim Jablon
Status: newassigned

I'll try a patch for solution 1

comment:3 Changed 6 years ago by Joachim Jablon

Cc: joachim@… added
Has patch: set

comment:4 Changed 6 years ago by Joachim Jablon

comment:5 Changed 6 years ago by Tim Graham

Resolution: fixed
Status: assignedclosed

In fd78fb82d633a23e04eac72c7e1f41cac75e4c5b:

Fixed #27138 -- Restored pre-Python 3.6 behavior of localtime() and make_naive() on Python 3.6.

Reverted test changes in a7a7ecd2b026c61a39a46d2d7eced0e06a92c970 and
e43ea36b7681e43ea99505a2cf7550d4d36016b3 (refs #27025).

Note: See TracTickets for help on using tickets.
Back to Top