Show Deprecation Warnings in Zope2

"Jens W. Klein" <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Organization Klein & Partner KG
Message-ID <[email protected]>
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

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.