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

warnings system and inspect module disagree about #49095

Closed
exarkun mannequin opened this issue Jan 5, 2009 · 4 comments
Closed

warnings system and inspect module disagree about #49095

exarkun mannequin opened this issue Jan 5, 2009 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@exarkun
Copy link
Mannequin

exarkun mannequin commented Jan 5, 2009

BPO 4845
Nosy @amauryfa
Superseder
  • bpo-1180193: broken pyc files
  • 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 2009-01-05.16:55:35.750>
    created_at = <Date 2009-01-05.16:00:39.255>
    labels = ['type-bug', 'library']
    title = 'warnings system and inspect module disagree about'
    updated_at = <Date 2009-01-05.17:12:23.018>
    user = 'https://bugs.python.org/exarkun'

    bugs.python.org fields:

    activity = <Date 2009-01-05.17:12:23.018>
    actor = 'exarkun'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-01-05.16:55:35.750>
    closer = 'amaury.forgeotdarc'
    components = ['Library (Lib)']
    creation = <Date 2009-01-05.16:00:39.255>
    creator = 'exarkun'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 4845
    keywords = []
    message_count = 4.0
    messages = ['79159', '79161', '79164', '79168']
    nosy_count = 2.0
    nosy_names = ['exarkun', 'amaury.forgeotdarc']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '1180193'
    type = 'behavior'
    url = 'https://bugs.python.org/issue4845'
    versions = []

    @exarkun
    Copy link
    Mannequin Author

    exarkun mannequin commented Jan 5, 2009

    Here's a transcript demonstrating the disagreement:

    exarkun@charm:$ mkdir warningexample
    exarkun@charm:
    $ cd warningexample/
    exarkun@charm:/warningexample$ mkdir foo
    exarkun@charm:
    /warningexample$ touch foo/init.py
    exarkun@charm:/warningexample$ cat > foo/bar.py
    import warnings
    def foo():
    warnings.warn("foo")
    exarkun@charm:
    /warningexample$ python -c 'import foo.bar'
    exarkun@charm:/warningexample$ mv foo bar
    exarkun@charm:
    /warningexample$ python -c 'import bar.bar; bar.bar.foo()'
    bar/bar.py:3: UserWarning: foo
    warnings.warn("foo")
    exarkun@charm:/warningexample$ python -c 'import bar.bar, inspect;
    print inspect.getabsfile(bar.bar.foo)'
    /home/exarkun/warningexample/foo/bar.py
    exarkun@charm:
    /warningexample$

    Notice that the warning is emitted for the file bar/bar.py but the
    inspect module claims that the function which emitted the warning is
    defined in /home/exarkun/warningexample/foo/bar.py. It seems that the
    warning system has somehow noticed that the .pyc file has the wrong
    source file listed and has figured out the correct file name, whereas
    the inspect module is blindly following the contents of the .pyc file.

    It would be great if the inspect module were at least as good at
    figuring out filenames as the warnings system.

    @exarkun exarkun mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 5, 2009
    @exarkun
    Copy link
    Mannequin Author

    exarkun mannequin commented Jan 5, 2009

    Perhaps even more disconcerting is the disagreement between
    inspect.getabsfile(f) and inspect.getabsfile(inspect.getmodule(f)). The
    latter agrees with the warnings system, unlike the former which just
    looks at the filename in the .pyc.

    @amauryfa
    Copy link
    Member

    amauryfa commented Jan 5, 2009

    This is a duplicate of bpo-1180193. Does the patch there correct your
    problem?

    @amauryfa amauryfa closed this as completed Jan 5, 2009
    @exarkun
    Copy link
    Mannequin Author

    exarkun mannequin commented Jan 5, 2009

    After updating the patch there so that it can be applied, it does seem
    to address my issue. I added a comment there.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant