[Zope-dev] Show Deprecation Warnings in Zope2
Jens W. Klein
jens at bluedynamics.com
Mon Feb 16 13:09:24 CET 2015
In past in Zope2 it was possible to turn DeprecationWarnings on and off
in zope.conf by adding a snippet like:
<warnfilter>
action always
category exceptions.DeprecationWarning
</warnfilter>
I wondered by this is no longer possible. So I found the code
responsible for adding the filter here:
https://github.com/zopefoundation/Zope/blob/master/src/Zope2/Startup/warnfilter.py#L53
It adds a custom filter at the _end_ of the filters list (last digit =
1). See also
https://docs.python.org/2/library/warnings.html#warnings.filterwarnings
Now since Python 2.7 some defaults changed.
One is, that DeprecationWarnings are ignored by default. So the first
rule in the default Python 2.7 filters is to ignore DeprecationWarnings.
see also https://docs.python.org/2/using/cmdline.html#cmdoption-W
and we can check this in code (naked python)
>>> import warnings
>>> warnings.filters
[('ignore', None, <type 'exceptions.DeprecationWarning'>, None, 0),
('ignore', None, <type 'exceptions.PendingDeprecationWarning'>, None,
0), ('ignore', None, <type 'exceptions.ImportWarning'>, None, 0),
('ignore', None, <type 'exceptions.BytesWarning'>, None, 0)]
So with the zope.conf setting there is no possibility to override the
defaults: The list is processed from the head to tail and first match wins.
Is there any good reason to append the zope custom filter to the list?
If it would be prepended (which is also the default settings for
warnings.filterwarnings) all works as expected.
I can provide this tiny patch + pull request if the change is fine.
Jens Klein
--
Klein & Partner KG, member of BlueDynamics Alliance
More information about the Zope-Dev
mailing list