Code

Opened 7 years ago

Closed 7 years ago

Last modified 6 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: gregorth
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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.

Attachments (0)

Change History (5)

comment:1 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by anonymous

  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

comment:3 Changed 7 years ago by gregorth

  • Owner changed from anonymous to gregorth
  • Status changed from assigned to new

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to wontfix
  • Status changed from new to closed

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 Changed 6 years ago by gwilson

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.