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>