[Python-ideas] New scope for exception handlers

Nick Coghlan ncoghlan at gmail.com
Sat Apr 9 04:14:50 EDT 2016


On 9 April 2016 at 17:44, Steven D'Aprano <steve at pearwood.info> wrote:
> So if you still want to champion your proposal, it's not enough to
> demonstrate that it could be done. You're going to have to demonstrate
> not only a benefit from the change, but that the benefit is worth
> breaking other people's code.

Not just any code, but "try it and see if it works" name binding
idioms recommended in the reference documentation:
https://docs.python.org/3/howto/pyporting.html#use-feature-detection-instead-of-version-detection

It's also worth noting that when it comes to detecting this kind of
structural error, tools like pylint already do a good job of tracing
possible control flow problems:

$ cat > conditional_name_binding.py
try:
    pass
except:
    a = 1
print(a)

$ pylint -E --enable=invalid-name conditional_name_binding.py
No config file found, using default configuration
************* Module conditional_name_binding
C:  4, 4: Invalid constant name "a" (invalid-name)

More easily finding this kind of problem is one of the major
advantages of using static analysis tools in addition to dynamic
testing.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list