Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative import unexpectedly binds name #59803

Closed
anntzer mannequin opened this issue Aug 9, 2012 · 3 comments
Closed

relative import unexpectedly binds name #59803

anntzer mannequin opened this issue Aug 9, 2012 · 3 comments

Comments

@anntzer
Copy link
Mannequin

anntzer mannequin commented Aug 9, 2012

BPO 15598
Nosy @brettcannon, @benjaminp, @ericsnowcurrently, @anntzer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-08-09.01:47:35.011>
created_at = <Date 2012-08-09.00:18:07.140>
labels = ['invalid']
title = 'relative import unexpectedly binds name'
updated_at = <Date 2012-08-09.01:47:35.010>
user = 'https://github.com/anntzer'

bugs.python.org fields:

activity = <Date 2012-08-09.01:47:35.010>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2012-08-09.01:47:35.011>
closer = 'benjamin.peterson'
components = []
creation = <Date 2012-08-09.00:18:07.140>
creator = 'Antony.Lee'
dependencies = []
files = []
hgrepos = []
issue_num = 15598
keywords = []
message_count = 3.0
messages = ['167742', '167746', '167752']
nosy_count = 4.0
nosy_names = ['brett.cannon', 'benjamin.peterson', 'eric.snow', 'Antony.Lee']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue15598'
versions = ['Python 3.2']

@anntzer
Copy link
Mannequin Author

anntzer mannequin commented Aug 9, 2012

The language reference is clear:
"The from form does not bind the module name" (Section 6.12)

However, consider the following example:

  • package/init.py:
    foo = "FOO"
    from .foo import bar
    print(foo)
    os = "OS"
    from os import path
    print(os)

  • package/foo.py:
    foo = 42

Now "import package" results in printing:
<module 'pypackage.foo' from 'pypackage/foo.py'>
OS

i.e., the relative "from ... import" has not only bound "bar", but also "foo", which seems to contradict the documentation.
(I get the same behaviour using 3.2.3 as well as 2.7.3.)

@benjaminp
Copy link
Contributor

I don't think this is incorrect. Importing a submodule implicit sets its name in the package scope, which is __init__'s module scope.

@ericsnowcurrently
Copy link
Member

I agree with Benjamin. The name is not bound due to the from-import statement.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants