#33200: Consider "hiding" datetime/zoneinfo imports in django.utils.timezone
-------------------------------------+-------------------------------------
Reporter: Jaap Roes | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Utilities | Version: dev
Severity: Normal | Keywords: timezone datetime
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
During code review I've seen people using `from django.utils.timezone
import datetime` (and variations) on multiple occasions. Sometimes because
their IDE just autocompletes that import, sometimes under the false
assumption that these are a timezone aware variation of the stdlib's
datetime implementation.
The most recent iteration I came across can be seen here:
https://github.com/SmileyChris/easy-
thumbnails/pull/579#discussion_r729003666
Because importing `datetime`, `timedelta`, `zoneinfo` etc. from a module
called `timezone` "looks" reasonable people seem to assume that these are
valid imports and sometimes even assume these are Django specific
implementations.
An easy way to discourage these imports is aliasing them, i.e.:
{{{
import datetime as _datetime
import zoneinfo as _zoneinfo
}}}
I'm aware Django (or any Python project) is full of potential incorrect
import opportunities. But this one seems to pop up fairly regularly in my
experience and when combined with incorrect assumptions about what is
being imported can be a root cause of subtle bugs.
--
Ticket URL: <https://code.djangoproject.com/ticket/33200>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.9e8d49e32b8a7f356d0c3d7fe477517b%40djangoproject.com.