Skip to content

Instantly share code, notes, and snippets.

@caleb15
Created August 22, 2019 05:56
Show Gist options
  • Save caleb15/a05e10cf6117360dc84091bac63aeac9 to your computer and use it in GitHub Desktop.
Save caleb15/a05e10cf6117360dc84091bac63aeac9 to your computer and use it in GitHub Desktop.
file with type problems for testing type checkers
import django
import doesNotExist
import math
import inspect
from typing import List
class foo:
def constructor(self, x):
self.x = x
def f():
return "PyCon"
def g():
# caught by pytype and pyright but not mypy or pyre
return f() + 2019
# pytype is lenient so it wont complain about below function
# even thoguh it appends a int to a string list
def get_list(year: int) -> List[str]:
lst = ["PyCon"]
lst.append(year)
return [str(x) for x in lst]
# y doesn't exist on foo. Pytype doesn't catch this.
foo.y = 4
# foo is wrong type to pass into get_list
get_list(foo)
# this isn't typescript: "number" is not an acceptable type
a: number = 3
# softball: you can't assign a string to a int. Pytype doesn't catch this.
a: int = "3"
# currentframe() can return None
callingFrame = inspect.currentframe().f_back
# this should actually work
get_list(2019)
try:
x = math.log(-1)
except ValueError:
print(x) # pytype and pyre corretly catches this as an error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment