#36864: Automatic shell imports cannot reliably handle submodules
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Leland
| Boeman
Type: New feature | Status: assigned
Component: Core (Management | Version: 5.2
commands) |
Severity: Normal | Resolution:
Keywords: import_string, | Triage Stage: Accepted
submodule |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tim McCurrach):
I have a question about how `import_string()` should work when it is able
to import both modules and the various attributes of modules. I think the
ability to do that introduces some ambiguity - and would potentially be a
more significant breaking change than someone relying on exceptions being
raised when importing modules and the like.
Suppose we have:
{{{
├─ a.py
└─ b/
├─ __init__.py # Contains a function called c
└─ c.py
}}}
then:
{{{
from b import c # imports the function
import b.c # imports the module
}}}
And so it's not obvious what `import_string("b.c") should do.
If my reading of the linked werkzueg solution above, and of the currently
open PR are correct; they both first attempt to import a module, and only
when that fails do they then look for an attribute to import instead. This
is different to Natalia's suggestion of maintaining existing behaviour and
dropping back to module import only when that fails - which would be less
breaking.
--
Ticket URL: <https://code.djangoproject.com/ticket/36864#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019e74563556-efcb87fe-e553-4ed1-b3d4-d5a83650e0d4-000000%40eu-central-1.amazonses.com.