Opened 13 years ago
Closed 12 years ago
#17061 closed Cleanup/optimization (fixed)
Factor out "get a module-level object from a dotted path" function
Reported by: | Carl Meyer | Owned by: | Claude Paroz |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | james@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
We've got importlib.import_module, but we're missing a higher-level function that would take "x.y.z.foo" (and maybe a fallback default?) and return the actual object "foo" from the "x.y.z" module. Instead we've got the same .rsplit(1) code duplicated everywhere we need to do this.
One implementation we could steal is here: https://github.com/erikrose/django-tidings/blob/master/tidings/utils.py#L144
I was sure there was already a ticket for this, but can't seem to find it, so maybe I was wrong...
Attachments (2)
Change History (9)
comment:1 by , 13 years ago
Cc: | added |
---|
comment:2 by , 12 years ago
Owner: | changed from | to
---|
by , 12 years ago
Attachment: | 17061-1.diff added |
---|
comment:3 by , 12 years ago
Has patch: | set |
---|
follow-up: 5 comment:4 by , 12 years ago
My last doubt is about the name of the function. I've initially chosen import_module_from_path
, but should we name it import_object_from_path
orimport_attribute_from_path
as the imported name is not the module itself, but an attribute of the module (variable, function, class, ...)?
comment:5 by , 12 years ago
Replying to claudep:
My last doubt is about the name of the function. I've initially chosen
import_module_from_path
, but should we name itimport_object_from_path
orimport_attribute_from_path
as the imported name is not the module itself, but an attribute of the module (variable, function, class, ...)?
How about just import_from_path
or import_by_path
- since we really don't know what type of thing we are importing.
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
26 files changed, 133 insertions(+), 273 deletions(-)