-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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.simplefilter("once")
and warnings.warn()
print all occurrences of matching warnings, regardless of location
#125761
Comments
I can confirm this behaviour. But this seems weird that no one has ever noticed it so I'm wondering whether there is something I'm misunderstanding. cc @ncoghlan |
There's a docs ambiguity here, since it doesn't explicitly state how the three filters that suppress repeated warnings determine if a warning is a repeat:
Unlike the initial check against the filter definition, these definitions are not affected by which fields are defined in the filter string. This is why a filter like
So in the example, all 6 warnings are considered distinct, since they all have different messages. If you drop the distinguishing numbers from each of them, you'll see That's a genuine flaw in the docs, but the behaviour is as expected, so I'll adjust the labels accordingly. |
I will take a look! |
…nings module (pythongh-126326) (cherry picked from commit 10eeec2) Co-authored-by: 고병찬 <[email protected]>
…nings module (pythongh-126326) (cherry picked from commit 10eeec2) Co-authored-by: 고병찬 <[email protected]>
Thanks for the docs update @byungchanKo99! The main PR has been merged, and the backport PRs will automatically merge once their CI runs complete. It may be a while before the change goes lives on docs.python.org, though (almost always within 24 hours, but most often faster than that - building the full docs set with all its translations can take a while) |
…rnings module (gh-126330) (cherry picked from commit 10eeec2) Co-authored-by: 고병찬 <[email protected]>
…rnings module (gh-126331) (cherry picked from commit 10eeec2) Co-authored-by: 고병찬 <[email protected]>
Closing since completed and backported. Thank you all! |
Bug report
Bug description:
With warnings.simplefilter("module") and warnings.warn(), I ran
main.py
which runsfile1.py
(module) andfile2.py
(module) as shown below:*Memos:
"module" print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)
.main.py
:file1.py
:file2.py
:Then,
"module"
print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)` as shown below:Now with
warnings.simplefilter("once")
andwarnings.warn()
, I ranmain.py
which runsfile1.py
(module) andfile2.py
(module) as shown below:*Memos:
"once" print only the first occurrence of matching warnings, regardless of location
.warnings.filterwarnings("once")
.But "once" print all occurrences of matching warnings, regardless of location as shown below:
CPython versions tested on:
3.11
Operating systems tested on:
Linux, Windows
Linked PRs
The text was updated successfully, but these errors were encountered: