I’m not surprised that people might misread documentation:)
Unfortunately, it’s hard to see what’s happened in given case. No information at all. Probably, as it was guessed: " I think you have to run this after you import the library that’s spitting out the warnings".
This might “not work” only when your settings clash with warnings filtering in the application. Something like this:
# ./a.py
import warnings
warnings.filterwarnings("error") # by evil author
complex(1j,1j)
$ ./python -W ignore::DeprecationWarning a.py
Traceback (most recent call last):
File "/home/sk/src/cpython/a.py", line 3, in <module>
complex(1j,1j)
~~~~~~~^^^^^^^
DeprecationWarning: complex() argument 'real' must be a real number, not complex
But this looks for me as a bug in application. As in the mkdocs example in the current thread.
@mcepl Of course, I have swept in front of my own doorstep. This dicussion goes far deeper and is not only in my own interest and those using my software but for the thousands of developers that decided to visit the link How to ignore deprecation warnings in Python - Stack Overflow
That stackoverflow question and answer thread has a reason and i agree that we should not look into the symptoms but go the core of the problem which is to a) use stderr as the default channel to present the warning message b) do this at run time and not at installation time c) do it over and over again.
I would love to get a) b) and c) changed to make sure the deprecation handling is done better than so far.
I would point out that 380k people wanting to suppress a deprecation warning at some point in their lives does not not equate to 380k people who were then still unable to suppress the warnings and want the whole system ripped up. I know I’m one of that 380k and I think the warning system is pretty decent, giving precise control both in code and at the environment level.
There are some pretty large caveats with warnings at installation time that nobody’s mentioned:
Pip can’t know if you’re using the deprecated parts or not so it’ll have to warn about every deprecation in your entire dependency tree
You can’t reconfigure warnings into errors (e.g. in a test suite) to keep you notified of new relevant deprecations