#3446 closed (wontfix)
use a standard utililty function for importing a module from a string
Reported by: | Owned by: | Grzegorz Ślusarek | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There are several instances throughout the django code that roll their own module importing from a string. They should all use a single utility function instead.
Change History (5)
comment:1 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:4 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:5 by , 17 years ago
I was thinking something a little bigger than replacing just the one __import__
line, like several places where there is code like:
i = path.rfind('.') module, attr = path[:i], path[i+1:] try: mod = __import__(module, globals(), locals(), [attr]) except ImportError, e: raise ImproperlyConfigured, 'Error importing template source loader %s: "%s"' % (module, e) try: func = getattr(mod, attr) except AttributeError: raise ImproperlyConfigured, 'Module "%s" does not define a "%s" callable template source loader' % (module, attr)
but you are probably right in that these can differ slightly and it might not be worth the trouble.
Note:
See TracTickets
for help on using tickets.
I don't think this will make anything clearer. Almost everywhere we call
__import__
, it's only that single call. However, there are variations, because sometimes the last component is['']
, sometimes it's a non-empty string in the list and sometimes it's[]
(empty list). Each has special and necessary significance. So you'd be replacing a one-line call with a function call that takes more or less the same parameters -- net cost is an extra function call each time and you save having to type two sets of empty braces.