Skip to content

Instantly share code, notes, and snippets.

@mawillcockson
Created February 8, 2021 04:18
Show Gist options
  • Select an option

  • Save mawillcockson/a2f9297cfee24bf18d01b15954bf1c70 to your computer and use it in GitHub Desktop.

Select an option

Save mawillcockson/a2f9297cfee24bf18d01b15954bf1c70 to your computer and use it in GitHub Desktop.
[Python] linting bug
"""
neither pylint nor mypy catch this error, even with the most stringent checks
"""
def func() -> int:
"raises an exception"
raise RuntimeError("i can't do it :(")
try:
# var is never defined if func() raises an exception
var = func()
except RuntimeError:
pass
try:
print(var)
except NameError:
print("var does not exist")
# a common version of this issue
try:
file = open("probably does not exist")
except OSError:
print("couldn't open that file")
finally:
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment