Skip to content

python: do not alter warnings' filter #1017

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

Merged
merged 3 commits into from
Mar 27, 2025
Merged

python: do not alter warnings' filter #1017

merged 3 commits into from
Mar 27, 2025

Conversation

reyammer
Copy link
Collaborator

We recently added a couple of DeprecationWarnings, and to make sure users would see them, we also set warnings.simplefilter to always. However, this inadvertently modified the warnings' settings for all other modules as well. This is not nice.

This patch removes the edit to the simplefilter (going back to default) and uses stacklevels warn argument to increase the DeprecationWarning visibiilty. This is not a silver bullet as if one uses the deprecated property "three levels or more" deep, the warning is not visible.

To fix this limitation, python 3.12 added the skip_file_prefixes argument to warn (python/cpython#100840), but it's not worth using it and break compatibility with older versions of python. stacklevel=2 should not create any problems (see python/cpython#88462).

Fixes #1006.

We recently added a couple of `DeprecationWarning`s, and to make sure users would see them, we also set `warnings.simplefilter` to `always`. However, this inadvertently modified the warnings' settings for all other modules as well. This is not nice.

This patch removes the edit to the simplefilter (going back to default) and uses `stacklevel`s `warn` argument to increase the `DeprecationWarning` visibiilty. This is not a silver bullet as if one uses the deprecated property "three levels or more" deep, the warning is not visible.

Very recent versions of python added the `skip_file_prefixes` argument to `warn`, but it's not worth using it and break compatibility with older versions of python.
@reyammer reyammer merged commit 746fad2 into main Mar 27, 2025
75 checks passed
@reyammer reyammer deleted the py-fix-1006 branch March 27, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiprocessing DeprecationWarning after upgrading to 0.6.1
1 participant