Last active
May 3, 2018 01:06
-
-
Save danizen/50a9ca21b462581ca8e23e17f999ee63 to your computer and use it in GitHub Desktop.
test python linter for some basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Test the linter | |
""" | |
def real_uninitialized_problem(x): | |
""" | |
Real problem of uninitialized variable | |
""" | |
return x + y | |
def fake_uninitialized_with_if(x): | |
""" | |
Fake uninitialized variable due to if statement | |
""" | |
if isinstance(x, float): | |
y = 0.0 | |
elif isinstance(x, int): | |
y = 0 | |
else: | |
y = "" | |
return y+x | |
def fake_uninitialized_with_switch(x): | |
""" | |
Fake uninitalized variable due to dict/based switch | |
""" | |
cases = { | |
float: 0.0, | |
int: 0 | |
} | |
if type(x) in cases: | |
y = cases[type(x)] | |
else: | |
y = "" | |
return y + x | |
def real_uninitialized_with_if(x): | |
""" | |
A real problem because y is not unitialized in an else case | |
""" | |
if isinstance(x, (int, float)): | |
y = 0.0 | |
elif isinstance(x, str): | |
y = "" | |
return y + x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment