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:
- maintain the current API, check for naive datetimes and raise an exception,
- 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 , 8 years ago
Component: | Uncategorized → Utilities |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:5 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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).
I'll try a patch for solution 1