-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use of warnings.catch_warnings resets the global warnings registry #2690
Comments
The answer is to stop using the code that's showing the warnings, or report and ignore them if they're in other libraries. "Warnings are even more visible" isn't really a bad thing. |
The reason it's used is to prevent functions that call other functions that take the same deprecated arguments from showing two warnings one of which is not addressable by users. |
That I realized, which is why I don't have a real clean way to work-around the issue. One way would be to use a thread-local flag or some such to disable the generation of the non-user-addressable warnings — admittedly, a messy solution. |
I don't plan to add more complexity to the warnings, they're meant to be low overhead. I can remove |
Standby. Let me try (removing the |
I can not speak for others, but, having now tried both options, I definitely prefer the version without the My use case (the one that caused me to open this issue, at least) is Lektor — see lektor/lektor#1142. Lektor forces its warnings filter to
continuing on with multiple identical warnings printed for each page rendered. With werkzeug's
In this case, at least, I don't think the numerous repeated identical warnings do anyone any good. With Footnotes
|
Thanks for investigating and making a PR, I've marked this for 2.3.4. |
There is a long-standing bug in Python python/cpython#73858 whereby any use of
warnings.catch_warnings
causes all memory of which warnings have already been displayed to be lost. So warnings whose action is configured as "default" (meaning show once for each module/line-number) get displayed multiple (possibly many, many) times.Note that use of
catch_warnings
resets memory of what warnings have been displayed globally — use ofcatch_warnings
by werkzeug can cause redisplay of unrelated warnings from other modules.PR #2608 (19d55c1) introduced a lot of new uses of
catch_warnings
.I'm not sure what the clean way is to work-around the issue, but it would be nice not to break the "default" warning action so drastically.
Example:
too-verbose.py
:Running
will elicit 10
url_parse
deprecation warnings. (The default warnings filter specifies an action of "default" for DeprecationWarnings, which means that they should be displayed just once per location.)Environment:
The text was updated successfully, but these errors were encountered: