From c0db4ed95908c0774815da22d4e810c2a5a7a266 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 24 Feb 2022 08:03:07 +0100 Subject: prefix numbers to puzzles --- check_checkers.py | 4 +++- issues.toml | 9 +++++---- puzzles/00_assign_wrong_type.py | 1 + puzzles/01_assign_reassign.py | 2 ++ puzzles/02_append.py | 2 ++ puzzles/03_assign_wrong_type_in_func.py | 2 ++ puzzles/10_infer_return_type.py | 3 +++ puzzles/20_enum_in_literal.py | 8 ++++++++ puzzles/30_try_except_finally.py | 8 ++++++++ puzzles/40_recursive_types.py | 3 +++ puzzles/50_typevar_constrained.py | 9 +++++++++ puzzles/easy.py | 1 - puzzles/easy_reassign.py | 2 -- puzzles/infer_append.py | 2 -- puzzles/infer_return_basic.py | 3 --- puzzles/tricky_enum.py | 8 -------- puzzles/tricky_recursive.py | 3 --- puzzles/tricky_try_except.py | 8 -------- puzzles/tricky_typevar_constrained.py | 9 --------- 19 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 puzzles/00_assign_wrong_type.py create mode 100644 puzzles/01_assign_reassign.py create mode 100644 puzzles/02_append.py create mode 100644 puzzles/03_assign_wrong_type_in_func.py create mode 100644 puzzles/10_infer_return_type.py create mode 100644 puzzles/20_enum_in_literal.py create mode 100644 puzzles/30_try_except_finally.py create mode 100644 puzzles/40_recursive_types.py create mode 100644 puzzles/50_typevar_constrained.py delete mode 100644 puzzles/easy.py delete mode 100644 puzzles/easy_reassign.py delete mode 100644 puzzles/infer_append.py delete mode 100644 puzzles/infer_return_basic.py delete mode 100644 puzzles/tricky_enum.py delete mode 100644 puzzles/tricky_recursive.py delete mode 100644 puzzles/tricky_try_except.py delete mode 100644 puzzles/tricky_typevar_constrained.py diff --git a/check_checkers.py b/check_checkers.py index 1a883b3..90ccc43 100755 --- a/check_checkers.py +++ b/check_checkers.py @@ -219,7 +219,9 @@ def run( if not expected: checker_issues = issues.get(checker.__class__.__name__.lower(), {}) issue = checker_issues.get( - os.path.splitext(os.path.basename(puzzle))[0] + os.path.splitext(os.path.basename(puzzle))[0].split( + '_', maxsplit=1 + )[1] ) if issue: out.write('
(') diff --git a/issues.toml b/issues.toml index a840797..55104e2 100644 --- a/issues.toml +++ b/issues.toml @@ -1,7 +1,8 @@ [mypy] -infer_return_basic = "mypy intentionally treats unannotated functions as returning Any" -tricky_recursive = 'issue 731' -tricky_typevar_constrained = 'issue 11880' +assign_wrong_type_in_func = "mypy does not check unannotated functions" +infer_return_type = "mypy treats unannotated functions as returning Any" +recursive_types = 'issue 731' +typevar_constrained = 'issue 11880' [pytype] -tricky_enum = 'issue 790' +enum_in_literal = 'issue 790' diff --git a/puzzles/00_assign_wrong_type.py b/puzzles/00_assign_wrong_type.py new file mode 100644 index 0000000..6298e46 --- /dev/null +++ b/puzzles/00_assign_wrong_type.py @@ -0,0 +1 @@ +x: int = 'Python' # error diff --git a/puzzles/01_assign_reassign.py b/puzzles/01_assign_reassign.py new file mode 100644 index 0000000..aeed688 --- /dev/null +++ b/puzzles/01_assign_reassign.py @@ -0,0 +1,2 @@ +x = 3 +x = 'test' # maybe error diff --git a/puzzles/02_append.py b/puzzles/02_append.py new file mode 100644 index 0000000..3511512 --- /dev/null +++ b/puzzles/02_append.py @@ -0,0 +1,2 @@ +lst = ["duck"] +lst.append(2022) # maybe error diff --git a/puzzles/03_assign_wrong_type_in_func.py b/puzzles/03_assign_wrong_type_in_func.py new file mode 100644 index 0000000..6c87c71 --- /dev/null +++ b/puzzles/03_assign_wrong_type_in_func.py @@ -0,0 +1,2 @@ +def f(): + x: int = 'Python' # error diff --git a/puzzles/10_infer_return_type.py b/puzzles/10_infer_return_type.py new file mode 100644 index 0000000..2776442 --- /dev/null +++ b/puzzles/10_infer_return_type.py @@ -0,0 +1,3 @@ +def f(): return "Python" + +f() + 3 # error diff --git a/puzzles/20_enum_in_literal.py b/puzzles/20_enum_in_literal.py new file mode 100644 index 0000000..a743168 --- /dev/null +++ b/puzzles/20_enum_in_literal.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/30_try_except_finally.py b/puzzles/30_try_except_finally.py new file mode 100644 index 0000000..d63ab10 --- /dev/null +++ b/puzzles/30_try_except_finally.py @@ -0,0 +1,8 @@ +def foo() -> None: + file = None + try: + file = open('test.json') + except Exception: + return None + finally: + file.name # error diff --git a/puzzles/40_recursive_types.py b/puzzles/40_recursive_types.py new file mode 100644 index 0000000..5de796c --- /dev/null +++ b/puzzles/40_recursive_types.py @@ -0,0 +1,3 @@ +from typing import Union + +Foo = list[Union['Foo', int]] diff --git a/puzzles/50_typevar_constrained.py b/puzzles/50_typevar_constrained.py new file mode 100644 index 0000000..50ce10a --- /dev/null +++ b/puzzles/50_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) diff --git a/puzzles/easy.py b/puzzles/easy.py deleted file mode 100644 index 6298e46..0000000 --- a/puzzles/easy.py +++ /dev/null @@ -1 +0,0 @@ -x: int = 'Python' # error diff --git a/puzzles/easy_reassign.py b/puzzles/easy_reassign.py deleted file mode 100644 index aeed688..0000000 --- a/puzzles/easy_reassign.py +++ /dev/null @@ -1,2 +0,0 @@ -x = 3 -x = 'test' # maybe error diff --git a/puzzles/infer_append.py b/puzzles/infer_append.py deleted file mode 100644 index 3511512..0000000 --- a/puzzles/infer_append.py +++ /dev/null @@ -1,2 +0,0 @@ -lst = ["duck"] -lst.append(2022) # maybe error diff --git a/puzzles/infer_return_basic.py b/puzzles/infer_return_basic.py deleted file mode 100644 index c2cbe7a..0000000 --- a/puzzles/infer_return_basic.py +++ /dev/null @@ -1,3 +0,0 @@ -def f(): return "Python" - -def g(): return f() + 3 # error diff --git a/puzzles/tricky_enum.py b/puzzles/tricky_enum.py deleted file mode 100644 index a743168..0000000 --- a/puzzles/tricky_enum.py +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 5de796c..0000000 --- a/puzzles/tricky_recursive.py +++ /dev/null @@ -1,3 +0,0 @@ -from typing import Union - -Foo = list[Union['Foo', int]] diff --git a/puzzles/tricky_try_except.py b/puzzles/tricky_try_except.py deleted file mode 100644 index d63ab10..0000000 --- a/puzzles/tricky_try_except.py +++ /dev/null @@ -1,8 +0,0 @@ -def foo() -> None: - file = None - try: - file = open('test.json') - except Exception: - return None - finally: - file.name # error diff --git a/puzzles/tricky_typevar_constrained.py b/puzzles/tricky_typevar_constrained.py deleted file mode 100644 index 50ce10a..0000000 --- a/puzzles/tricky_typevar_constrained.py +++ /dev/null @@ -1,9 +0,0 @@ -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) -- cgit v1.2.3