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

[2.7] bpo-32524: Don't leak a package's __init__.py module object in sys.modules on SyntaxError #5142

Closed

Conversation

segevfiner
Copy link
Contributor

@segevfiner segevfiner commented Jan 9, 2018

With the file hello/__init__.py:

ham = 123
spam()spam()

I get the following:

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "hello\__init__.py", line 2
    spam()spam()
             ^
SyntaxError: invalid syntax
>>> import hello
>>> print hello
<module 'hello' from 'hello'>
>>> print dir(hello)
['__doc__', '__file__', '__name__', '__package__', '__path__']
>>>

I'd expect to get the SyntaxError twice, which is indeed what happens on at least Python 3.6 (Possibly earlier Python 3 versions).

Originally found here pallets/flask#2423 & pallets/flask#2588

cc @davidism @mitsuhiko

https://bugs.python.org/issue32524

@segevfiner segevfiner force-pushed the bpo-32524-init-py-syntax-error-bug branch from 6883f30 to bb0618a Compare January 9, 2018 21:42
@csabella csabella closed this Jan 12, 2020
@segevfiner segevfiner deleted the bpo-32524-init-py-syntax-error-bug branch January 12, 2020 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants