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/2008-March/078057.html below:

[Python-Dev] Proposal: Slightly Changed Semantics for from-Import

[Python-Dev] Proposal: Slightly Changed Semantics for from-Import [Python-Dev] Proposal: Slightly Changed Semantics for from-ImportArmin Ronacher armin.ronacher at active-4.com
Sat Mar 22 12:53:14 CET 2008
Hi all,


I propose a small change on the "from"-import behavior.  Currently there are two
ways to import a module name foo from bar.  Namely "import foo.bar as bar" and
"from foo import bar".  The main problem with the second is that it will not
work in every situation.

Modules are registered with their names in sys.modules before the import but
become and attribute of their parent after.  This leads to the surprising
behavior that "from foo.bar import baz" works but "from foo import bar" not
until the foo.bar module finished setting up.

This behavior is especially surprising if you have circular dependencies and you
notice that your imports work properly if you import a specific module before
another one and will fail if you import it afterwards although it doesn't seem
like that should make any difference.

My proposal is that "from foo import bar" returns sys.modules["foo.bar"] if this
one exists and the foo.bar attribute lookup failed.

If a test case is needed I can attach one later on.


Regards,
Armin

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