diff options
Diffstat (limited to 'puzzles')
-rw-r--r-- | puzzles/easy.py | 1 | ||||
-rw-r--r-- | puzzles/easy_reassign.py | 2 | ||||
-rw-r--r-- | puzzles/infer_append.py | 2 | ||||
-rw-r--r-- | puzzles/infer_return_basic.py | 3 | ||||
-rw-r--r-- | puzzles/tricky_enum.py | 8 | ||||
-rw-r--r-- | puzzles/tricky_recursive.py | 3 | ||||
-rw-r--r-- | puzzles/tricky_try_except.py | 8 | ||||
-rw-r--r-- | puzzles/tricky_typevar_constrained.py | 9 |
8 files changed, 36 insertions, 0 deletions
diff --git a/puzzles/easy.py b/puzzles/easy.py new file mode 100644 index 0000000..6298e46 --- /dev/null +++ b/puzzles/easy.py @@ -0,0 +1 @@ +x: int = 'Python' # error diff --git a/puzzles/easy_reassign.py b/puzzles/easy_reassign.py new file mode 100644 index 0000000..aeed688 --- /dev/null +++ b/puzzles/easy_reassign.py @@ -0,0 +1,2 @@ +x = 3 +x = 'test' # maybe error diff --git a/puzzles/infer_append.py b/puzzles/infer_append.py new file mode 100644 index 0000000..3511512 --- /dev/null +++ b/puzzles/infer_append.py @@ -0,0 +1,2 @@ +lst = ["duck"] +lst.append(2022) # maybe error diff --git a/puzzles/infer_return_basic.py b/puzzles/infer_return_basic.py new file mode 100644 index 0000000..c2cbe7a --- /dev/null +++ b/puzzles/infer_return_basic.py @@ -0,0 +1,3 @@ +def f(): return "Python" + +def g(): return f() + 3 # error diff --git a/puzzles/tricky_enum.py b/puzzles/tricky_enum.py new file mode 100644 index 0000000..a743168 --- /dev/null +++ b/puzzles/tricky_enum.py @@ -0,0 +1,8 @@ +import enum +from typing import Literal + +class Color(enum.Enum): + Red = enum.auto() + Blue = enum.auto() + +c: Literal[Color.Red] = Color.Blue # error diff --git a/puzzles/tricky_recursive.py b/puzzles/tricky_recursive.py new file mode 100644 index 0000000..5de796c --- /dev/null +++ b/puzzles/tricky_recursive.py @@ -0,0 +1,3 @@ +from typing import Union + +Foo = list[Union['Foo', int]] diff --git a/puzzles/tricky_try_except.py b/puzzles/tricky_try_except.py new file mode 100644 index 0000000..de829c3 --- /dev/null +++ b/puzzles/tricky_try_except.py @@ -0,0 +1,8 @@ +def foo(): + file = None + try: + file = open('test.json') + except Exception: + pass + + file.name # error diff --git a/puzzles/tricky_typevar_constrained.py b/puzzles/tricky_typevar_constrained.py new file mode 100644 index 0000000..50ce10a --- /dev/null +++ b/puzzles/tricky_typevar_constrained.py @@ -0,0 +1,9 @@ +from typing import TypeVar, Any, Union + +V = TypeVar("V", str, bytes) + +def check_v(x: Union[V, list[V]]) -> V: + raise NotImplementedError() + +def foo(a: list[Any]): + check_v(a) |