Visitar URL original
linecache cannot get source for the __main__ module with a custom loader · Issue #86291 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20231101191607/https://github.com/python/cpython/issues/86291
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

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

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.10 only 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
  • bpo-42125: 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']

    @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
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only 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

    1 participant