This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python 2.7 leaks a packages __init__.py module object on SyntaxError
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Segev Finer
Priority: normal Keywords: patch

Created on 2018-01-09 21:12 by Segev Finer, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5142 closed Segev Finer, 2018-01-09 21:21
Messages (1)
msg309736 - (view) Author: Segev Finer (Segev Finer) * Date: 2018-01-09 21:12
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 https://github.com/pallets/flask/issues/2423 & https://github.com/pallets/flask/pull/2588

I'm going to submit a PR with a fix.
History
Date User Action Args
2022-04-11 14:58:56adminsetgithub: 76705
2020-01-12 00:50:52cheryl.sabellasetstatus: open -> closed
resolution: wont fix
stage: patch review -> resolved
2018-01-09 21:21:22Segev Finersetkeywords: + patch
stage: patch review
pull_requests: + pull_request5001
2018-01-09 21:12:50Segev Finercreate