[Python-Dev] syntax warnings don't go through warnings.warn?

Dino Viehland dinov at microsoft.com
Mon Jun 1 18:50:19 CEST 2009


I'm just a little surprised by this - Is there a reason why syntax warnings are special and untrappable via warnings.warn?

>>> import warnings
>>> def mywarn(*args): print 'xx', args
...
>>> warnings.warn = mywarn
>>> compile("def f():\n    a = 1\n    global a\n", "", "exec")
:3: SyntaxWarning: name 'a' is assigned to before global declaration
<code object <module> at 012DB410, file "", line 1>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090601/1e0511ea/attachment.htm>


More information about the Python-Dev mailing list