#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 Leland Boeman):

 I've poked around here a bit and it has been fun to get to know Python's
 import system a little better. Thanks for calling that out Tim. I hadn't
 considered that case before.

 I have implemented the suggested behavior of falling back to load_module
 after getattr fails. This should follow the behavior of `from b import c`
 as suggested in the docs and I believe it is the best way forward  and
 least breaking as has been previously discussed.

 I was surprised by Python's import behavior around name collisions between
 objects defined by a module and it's submodules.

 Given the example from above:
 {{{
 ├─ a.py
 └─ b/
    ├─ __init__.py    # Contains a function called c
    └─ c.py
 }}}

 What the user receives from the `from b import c` statement is determined
 by whether or not the module `b.c` has been previously loaded.  This is
 also true for the existing implementation of `import_string`, with the
 exception that currently `import_string` raises when `b.c` has not been
 previously loaded.

 If we adopt this behavior, I think it would be helpful to users to call
 out this case in the docs. It could also be argued that equivalence to
 `from module import x` noted in the docs is enough of an explanation.

 I have some house keeping updates and some comments on the PR to address,
 but wanted to check if this all seems agreeable before proceeding.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36864#comment:15>
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/0107019e7aeff50a-1c00b435-835b-4b03-8bc4-d81bdd331731-000000%40eu-central-1.amazonses.com.

Reply via email to