[Python-Dev] Can Python implementations reject semantically invalid expressions? (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Jul 3 03:31:18 CEST 2010


Steven D'Aprano wrote:

if the keyhole optimizer raised SyntaxError (or some other exception) on seeing this:

def f(): return 1 + "1"

That might break code that was deliberately trying to raise an exception. Sometimes you see things like

try: 1/0 except Exception, e: ...

Usually this kind of thing is only done in test code or illustrative snippets, but even so, it should work as expected.

-- Greg



More information about the Python-Dev mailing list