#14675 closed Cleanup/optimization (fixed)
Update docs and project template to avoid "import *" for url patterns
Reported by: | Rob Hudson | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Now that we have http://code.djangoproject.com/changeset/13590, we should probably avoid the import *
for urls in our docs and project template.
Attachments (11)
Change History (27)
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
by , 14 years ago
Attachment: | template.diff added |
---|
Explicitly included functions from urls.default for the project template.
by , 14 years ago
Attachment: | django-itself.diff added |
---|
Explicitly included functions from urls.default in django itself.
by , 14 years ago
Attachment: | contrib-apps.diff added |
---|
Explicitly included functions from urls.default in contrib apps.
by , 14 years ago
Explicitly included functions from urls.default in documentation.
by , 14 years ago
Attachment: | contrib-apps-docs.diff added |
---|
Explicitly included functions from urls.default in documentation for contrib apps.
by , 14 years ago
Attachment: | tests.diff added |
---|
Explicitly included functions from urls.default in tests.
comment:3 by , 14 years ago
Hello,
I wanted to make my first contribution to Django and this looked simple enough, I hope I did it correctly. My goal with this set of patches was to totally eradicate the import of * from urls.default. I've separated it in various parts so it's easy to pick what you consider is the correct set of changes starting with the small change to the template for new projects up to modifying every contrib app and test to follow this best practices.
comment:4 by , 14 years ago
Oh, something I didn't modify is the documentation for Django < 1.3, as I presume that should be left alone as it is now.
comment:5 by , 14 years ago
I'm totally in favour of deprecating the star import, as it's something that's bugged me previously.
After a cursory glance of the changeset and the diffs pupeno has provided, I'd like to suggest that the documentation diff may need further work, to clarify the change as it affects handler404 & handler500.
Mostly, That takes care of setting ``handler404`` in the current module. [...]
occurs in a couple of places, and whilst still semi-accurate now that we fallback instead of grabbing via a star import, it feels like further explanation might be expounded. However, as the changeset doesn't seem to have any doc changes, I'm not sure if this is already covered elsewhere.
comment:6 by , 14 years ago
Component: | Documentation → Core framework |
---|---|
Has patch: | set |
Patch needs improvement: | set |
Agreed with Keryn Knight that a few words in the docs would be helpful. However, this change is much more relevant to the rest of the codebase than it is to the docs, so I'm changing the component.
I have not tested this patch. Someone needs to apply it against trunk and verify that it passes the full test suite as well.
by , 14 years ago
Attachment: | 14675-remove-import-star-from-urlconfs.patch added |
---|
all-in-one patch, & fixed typo in regressiontests/urlpatterns_reverse/included_named_urls2.py
by , 14 years ago
Attachment: | 14675-remove-import-star-from-urlconfs-2.patch added |
---|
all-in-one patch, with tweaked docs and made from django.conf.urls import patterns
work (& the standard way to import url functions)
comment:7 by , 14 years ago
It struck me that we're making things awfully verbose by getting rid of the 'import *'...
So to compensate, I removed the '.defaults', which has always bugged me.
It's just easier to remember than 'from django.conf.urls.defaults import patterns'. The 'defaults' should be implied.
This shouldn't break anything, the code is still in defaults.py.
comment:8 by , 14 years ago
Patch needs improvement: | unset |
---|
comment:10 by , 14 years ago
Based on discussion in IRC with Alex and Russell, adding the ability to import from just "django.conf.urls" is good, but a feature not a bugfix, so not a candidate for 1.3 at this point. And we don't want to do two passes through all the contrib apps etc, so we're just going to hold off on the rest of this patch until after 1.3 is released.
comment:12 by , 14 years ago
milestone: | 1.3 → 1.4 |
---|
Changing the milestone as per Carl's comment above.
comment:13 by , 14 years ago
milestone: | 1.4 |
---|---|
Severity: | → Normal |
Type: | → Cleanup/optimization |
comment:14 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
14675-remove-import-star-from-urlconfs-2.patch fails to apply cleanly on to trunk
by , 14 years ago
Attachment: | 14675-remove-import-star-from-urlconfs-3.patch added |
---|
by , 13 years ago
Attachment: | 14675-remove-import-star-from-urlconfs-4.patch added |
---|
Patch updated to apply cleanly as of now
I've often been bothered by the from
django.conf.urls.defaults import *
pattern myself, since we so often encourage people not to useimport *
. While technically that module does define__all__
, I'd still rather seepatterns
,url
,include
, et. al. imported explicitly anyway. So I'm all for this change.