[docs] [issue22243] Documentation on try statement incorrectly implies target of except clause can be any assignable expression

Michael Williamson report at bugs.python.org
Fri Aug 22 23:10:44 CEST 2014


Michael Williamson added the comment:

> Using 'expression' (or 'expr' in the ast doc) for what should be 'exceptions: identifier' or paranthesized tuple of identifiers;, is also too broad. However, that must be enforced in the compiler rather than the parser, and compiler restrictions are in the text, not the grammar.

I would expect any expression to be valid so long as it evaluates at runtime to an exception type (or tuple of exception types), so the use of expression seems correct to me. In other words, the following is valid Python (but would not be allowed if I've understood your statement correctly):

    def f():
        try:
            "".blah
        except some_error():
            print("caught")
            
    def some_error():
        return AttributeError

    f()

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22243>
_______________________________________


More information about the docs mailing list