Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pure-Python warn_explicit() passes wrong arg to WarningMessage #129843

Closed
Labels
easystdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@jwilk

Description

@jwilk

The pure-Python implementation of thewarnings.warn_explicit() function does this:

msg=WarningMessage(message,category,filename,lineno,source)

But the 5th argument ofWarningMessage isfile (the file the message is supposed to be printed into), notsource ("the destroyed object which emitted aResourceWarning").

Here's how to reproduce the bug:

>>>import sys, importlib, warnings>>> warnings.warn_explicit('eggs',UserWarning,'eggs.py',42,source=object())eggs.py:42: UserWarning: eggsObject allocated at (most recent call last):  File "<stdin>", lineno 1>>># so far so good; now let's try the same with pure-Python implementation>>> sys.modules['_warnings']=None>>> importlib.reload(warnings)<module 'warnings' from '/usr/lib/python3.12/warnings.py'>>>> warnings.warn_explicit('eggs',UserWarning,'eggs.py',42,source=object())Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/usr/lib/python3.12/warnings.py", line 413, in warn_explicit    _showwarnmsg(msg)  File "/usr/lib/python3.12/warnings.py", line 115, in _showwarnmsg    _showwarnmsg_impl(msg)  File "/usr/lib/python3.12/warnings.py", line 30, in _showwarnmsg_impl    file.write(text)    ^^^^^^^^^^AttributeError: 'object' object has no attribute 'write'

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    easystdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp