A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-December/041011.html below:

[Python-Dev] Re: Christmas Wishlist

[Python-Dev] Re: Christmas Wishlist [Python-Dev] Re: Christmas WishlistEdward Loper edloper at gradient.cis.upenn.edu
Mon Dec 15 13:44:56 EST 2003
Barry Warsaw <barry at python.org> wrote:
> Actually, if truth be told, I'd love to just ban local imports.  I
> understand that might be controversial though <wink>.

+1 (asuming that you're talking about package-local imports).

I've seen a couple people get bitten by the fact that a module gets 
loaded twice if there are separate local & global imports for it:

     % mkdir pkg

     % touch pkg/__init__.py

     % cat >pkg/a.py
     print 'A is being imported (not re-used)'
     class A: pass

     % cat >pkg/b.py
     from a import A as LocalA
     from pkg.a import A as GlobalA
     print isinstance(LocalA(), GlobalA)
     print isinstance(GlobalA(), LocalA)

     % PYTHONPATH=.; python pkg/b.py
     A is being imported (not re-used)
     A is being imported (not re-used)
     0
     0

Since pkg/a gets loaded twice, we end up with two versions of class A, 
which are not compatible.  In practice this usually comes up if a 
package uses local imports between submodules, and then an outside user 
uses a global import to get a submodule.

-Edward



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4