[Import-SIG] Dabeaz's weird import discovery

Barry Warsaw barry at python.org
Wed Apr 22 19:09:42 CEST 2015


On Apr 22, 2015, at 09:21 AM, Ethan Furman wrote:

>I see that it's intentional, but why is it fundamental?

Fundamental in the sense that it's the importlib machinery, not any particular
loader, that does the name binding.

It's not fundamental in that the import machinery *has* to work this way.  In
fact, if I was reviewing the code today, I'd red flag this.

>> What was the motivation for this?  Was the intent really to bind submodule
>> names in the parent module seemingly magically?
>
>I have to say I don't care for this.  In the cases where I'm importing sub-
>modules into __init__ I'm usually trying to keep a neat namespace, and with
>this behavior I'll have more work to do... although probably not a big deal
>with __all__ in the picture, so I could live with it if it is indeed
>"fundamental".  ;)

It's certainly surprising!  I don't think it saves much typing.  If it wasn't
already relied upon by existing code, I'd suggest removing it.  Clearly there
was a reason why it was added, although there's no clue that I can find as to
what that reason was.

If it's just a quirk of importlib that we have to live with now, let's at
least document it.

Cheers,
-Barry


More information about the Import-SIG mailing list