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

linecache cannot get source for the __main__ module with a custom loader #86291

Closed
eltoder mannequin opened this issue Oct 23, 2020 · 1 comment
Closed

linecache cannot get source for the __main__ module with a custom loader #86291

eltoder mannequin opened this issue Oct 23, 2020 · 1 comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-importlib type-bug An unexpected behavior, bug, or error

Comments

@eltoder
Copy link
Mannequin

eltoder mannequin commented Oct 23, 2020

BPO 42125
Nosy @ncoghlan, @vstinner, @eltoder, @FFY00
PRs
  • gh-86291: linecache: get module name from __spec__ if available #22908
  • Files
  • t.zip
  • 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 = None
    created_at = <Date 2020-10-23.05:26:53.150>
    labels = ['type-bug', 'library', '3.10']
    title = 'linecache cannot get source for the __main__ module with a custom loader'
    updated_at = <Date 2021-05-29.17:12:41.769>
    user = 'https://github.com/eltoder'

    bugs.python.org fields:

    activity = <Date 2021-05-29.17:12:41.769>
    actor = 'FFY00'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-10-23.05:26:53.150>
    creator = 'eltoder'
    dependencies = []
    files = ['49536']
    hgrepos = []
    issue_num = 42125
    keywords = ['patch']
    message_count = 1.0
    messages = ['379408']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'vstinner', 'python-dev', 'eltoder', 'FFY00']
    pr_nums = ['22908']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42125'
    versions = ['Python 3.10']

    Linked PRs

    @eltoder
    Copy link
    Mannequin Author

    eltoder mannequin commented Oct 23, 2020

    If a module has a loader, linecache calls its get_source() passing __name__ as the argument. This works most of the time, except that the __main__ module has it set to "__main__", which is commonly not the real name of the module. Luckily, we now have __spec__ which has the real name, so we can just use it.

    Attached zip file reproduces the problem:
    $ python t.zip
    Traceback (most recent call last):
      ...
      File "t.zip/t.py", line 11, in <module>
      File "t.zip/t.py", line 8, in f
      File "t.zip/t.py", line 8, in f
      File "t.zip/t.py", line 8, in f
      [Previous line repeated 2 more times]
      File "t.zip/t.py", line 7, in f
    ValueError

    Note that entries from t.py don't have source code lines.

    @eltoder eltoder mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 23, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @erlend-aasland erlend-aasland removed the 3.10 only security fixes label Jan 16, 2024
    serhiy-storchaka pushed a commit that referenced this issue Feb 20, 2024
    …2908)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2024
    …pythonGH-22908)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    (cherry picked from commit e976bab)
    
    Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2024
    …pythonGH-22908)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    (cherry picked from commit e976bab)
    
    Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
    @serhiy-storchaka serhiy-storchaka added 3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Feb 20, 2024
    serhiy-storchaka pushed a commit that referenced this issue Feb 20, 2024
    GH-22908) (GH-115731)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    (cherry picked from commit e976bab)
    
    Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
    serhiy-storchaka pushed a commit that referenced this issue Feb 20, 2024
    GH-22908) (GH-115732)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    (cherry picked from commit e976bab)
    
    Co-authored-by: Eugene Toder <eltoder@users.noreply.github.com>
    woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
    …pythonGH-22908)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
    …pythonGH-22908)
    
    This allows getting source code for the __main__ module when a custom
    loader is used.
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-importlib type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants