Opened 8 years ago

Closed 8 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

Description

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 https://github.com/django/django/pull/7134#issuecomment-241388846 for a longer discussion of option 2.

Change History (5)

comment:1 by Aymeric Augustin, 8 years ago

Component: UncategorizedUtilities
Triage Stage: UnreviewedAccepted

comment:2 by Joachim Jablon, 8 years ago

Owner: changed from nobody to Joachim Jablon
Status: newassigned

I'll try a patch for solution 1

comment:3 by Joachim Jablon, 8 years ago

Cc: joachim@… added
Has patch: set

comment:4 by Joachim Jablon, 8 years ago

comment:5 by Tim Graham, 8 years ago

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