Opened 17 years ago

Closed 16 years ago

Last modified 16 years ago

#3446 closed (wontfix)

use a standard utililty function for importing a module from a string

Reported by: Gary Wilson <gary.wilson@…> 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 Gary Wilson <gary.wilson@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:2 by anonymous, 17 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:3 by Grzegorz Ślusarek, 17 years ago

Owner: changed from anonymous to Grzegorz Ślusarek
Status: assignednew

comment:4 by Malcolm Tredinnick, 16 years ago

Resolution: wontfix
Status: newclosed

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.

comment:5 by Gary Wilson, 16 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.
Back to Top