Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#1525 closed task (fixed)

Wildcard imports should be converted to explicit form

Reported by: pb@… Owned by: Adrian Holovaty
Component: Core (Other) Version: magic-removal
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Wildcard imports are generally frowned upon in the Python world. There are a handful of these in Django, most of them in urlconfs. Since they have been eschewed everywhere else in the codebase it seems worth cleaning up.

In the urlconfs I've tested, from django.conf.urls.defaults import patterns, include, handler404, handler500 seems to be a viable replacement.

Occurrences in magic-removal/django, r2542:

$ grep -nr 'import \*' . | grep -v .svn
./conf/project_template/urls.py:1:from django.conf.urls.defaults import *
./conf/urls/admin_password_reset.py:1:from django.conf.urls.defaults import *
./conf/urls/i18n.py:1:from django.conf.urls.defaults import *
./conf/urls/registration.py:1:from django.conf.urls.defaults import *
./conf/urls/shortcut.py:1:from django.conf.urls.defaults import *
./contrib/admin/urls.py:1:from django.conf.urls.defaults import *
./contrib/comments/urls/comments.py:1:from django.conf.urls.defaults import *
./contrib/flatpages/urls.py:1:from django.conf.urls.defaults import *
./core/template_loader.py:7:from django.template.loader import *
./db/models/__init__.py:5:from django.db.models.loading import *
./db/models/__init__.py:9:from django.db.models.fields import *
./db/models/__init__.py:10:from django.db.models.fields.related import *

Occurrences in magic-removal/docs, r2542:

$ grep -nr 'import \*' . | grep -v .svn
./generic_views.txt:34:    from django.conf.urls.defaults import *
./overview.txt:162:    from django.conf.urls.defaults import *
./static_files.txt:102:    from django.conf.urls.defaults import *
./syndication_feeds.txt:52:    from django.conf.urls.defaults import *
./syndication_feeds.txt:311:    from django.conf.urls.defaults import *
./tutorial03.txt:73:    from django.conf.urls.defaults import *
./tutorial03.txt:330:    from django.conf.urls.defaults import *
./tutorial04.txt:159:    from django.conf.urls.defaults import *
./tutorial04.txt:170:    from django.conf.urls.defaults import *
./url_dispatch.txt:56:    from django.conf.urls.defaults import *
./url_dispatch.txt:67:    * ``from django.conf.urls.defaults import *`` makes the ``patterns``
./url_dispatch.txt:170:Convention is to use ``from django.conf.urls.defaults import *`` at the top of
./url_dispatch.txt:259:    from django.conf.urls.defaults import *
./url_dispatch.txt:274:    from django.conf.urls.defaults import *
./url_dispatch.txt:296:    from django.conf.urls.defaults import *

Change History (2)

comment:1 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [2683]) magic-removal: Fixed #1525 -- Got rid of a few 'import *' calls

comment:2 by Adrian Holovaty, 18 years ago

IMO, the 'from django.conf.urls.defaults import *' lines are acceptable because of the savings of typing. I've changed the other import *'s, though.

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