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

Do not call warnings.simplefilter in library code #11140

Closed
vnmabus opened this issue Oct 28, 2024 · 3 comments · Fixed by #11141
Closed

Do not call warnings.simplefilter in library code #11140

vnmabus opened this issue Oct 28, 2024 · 3 comments · Fixed by #11141
Assignees

Comments

@vnmabus
Copy link

vnmabus commented Oct 28, 2024

What is the bug?

In https://github.com/OSGeo/gdal/blob/master/swig/python/osgeo/__init__.py warnings.simplefilter is called to always display deprecation warnings. This changes the global warnings configuration, which is bad to do inside a library.

In our case, this happened when using an older Python version and the newest GDAL that still supported it (which triggers a message saying that newer GDAL versions will drop support for that Python version). Due to the warnings.simplefilter change, a lot of deprecation warnings from other modules flooded our logs.

We are going to patch our GDAL version suppressing calls to warnings.simplefilter. However, as this is still happening in master I wanted to open an issue for it to be fixed in the future.

Steps to reproduce the issue

Just execute the newest GDAL which still has support for an older Python version.

Versions and provenance

GDAL 3.2.3 and Python 2.7 (but it will happen again when you drop support for another Python version).

Additional context

No response

@rouault
Copy link
Member

rouault commented Oct 28, 2024

@idanmiara Any thought about that? I see you added that in 339a600

@idanmiara
Copy link
Collaborator

I frankly don't remember why I set simplefilter('always', DeprecationWarning) there, but as @vnmabus suggests it also makes sense to me to remove both calls to simplefilter.

@rouault
Copy link
Member

rouault commented Oct 28, 2024

thanks, will be fixed per #11141

rouault added a commit that referenced this issue Oct 28, 2024
Fixes #11140

This changes the global warnings configuration, which is not appropriate
to do inside a library.
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 a pull request may close this issue.

3 participants