yugr / python-hate

A growing list of things I dislike about Python
51 stars 2 forks source link

Improve example of executed unreachable code #2

Closed master30f closed 1 year ago

master30f commented 1 year ago

The old example did not illustrate the problem very well, as it works even without the unreachable branch.

x = 1
def a():
    return x
print(a())  # Prints 1

This change fixes that by assigning to the global variable, which is not possible without the global keyword, thus better illustrating the execution of unreachable code.