From 676adfa06ed41c322c6f104922a7538af28d9e7f Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Sat, 21 Jan 2023 15:47:58 +0100 Subject: [PATCH 1/6] update mypy requirements to install tomli --- mypy-requirements.txt | 2 +- mypy/fastparse.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy-requirements.txt b/mypy-requirements.txt index ee5fe5d295b8..a3b51e4f1d32 100644 --- a/mypy-requirements.txt +++ b/mypy-requirements.txt @@ -2,4 +2,4 @@ typing_extensions>=3.10 mypy_extensions>=0.4.3 typed_ast>=1.4.0,<2; python_version<'3.8' -tomli>=1.1.0; python_version<'3.11' +tomli>=1.1.0; python_version<'3.12' diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 209ebb89f36b..5e7585ed355e 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -841,7 +841,7 @@ def translate_module_id(self, id: str) -> str: def visit_Module(self, mod: ast3.Module) -> MypyFile: self.type_ignores = {} for ti in mod.type_ignores: - parsed = parse_type_ignore_tag(ti.tag) # type: ignore[attr-defined] + parsed = parse_type_ignore_tag(ti.tag) if parsed is not None: self.type_ignores[ti.lineno] = parsed else: @@ -1566,7 +1566,7 @@ def visit_FormattedValue(self, n: ast3.FormattedValue) -> Expression: # to allow mypyc to support f-strings with format specifiers and conversions. val_exp = self.visit(n.value) val_exp.set_line(n.lineno, n.col_offset) - conv_str = "" if n.conversion is None or n.conversion < 0 else "!" + chr(n.conversion) + conv_str = "" if n.conversion is None or n.conversion < 0 else "!" + chr(n.conversion) # type: ignore[redundant-expr] format_string = StrExpr("{" + conv_str + ":{}}") format_spec_exp = self.visit(n.format_spec) if n.format_spec is not None else StrExpr("") format_string.set_line(n.lineno, n.col_offset) @@ -2010,10 +2010,10 @@ def visit_Subscript(self, n: ast3.Subscript) -> Type: for s in dims: if getattr(s, "col_offset", None) is None: if isinstance(s, ast3.Index): - s.col_offset = s.value.col_offset # type: ignore[attr-defined] + s.col_offset = s.value.col_offset elif isinstance(s, ast3.Slice): assert s.lower is not None - s.col_offset = s.lower.col_offset # type: ignore[attr-defined] + s.col_offset = s.lower.col_offset sliceval = ast3.Tuple(dims, n.ctx) empty_tuple_index = False From 9c68f6ecaab8647f56fd600fb7adfeae5cab5ada Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Sat, 21 Jan 2023 15:58:49 +0100 Subject: [PATCH 2/6] remove mypy # type: ignore[attr-defined] errors --- mypy/fastparse.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 5e7585ed355e..209ebb89f36b 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -841,7 +841,7 @@ def translate_module_id(self, id: str) -> str: def visit_Module(self, mod: ast3.Module) -> MypyFile: self.type_ignores = {} for ti in mod.type_ignores: - parsed = parse_type_ignore_tag(ti.tag) + parsed = parse_type_ignore_tag(ti.tag) # type: ignore[attr-defined] if parsed is not None: self.type_ignores[ti.lineno] = parsed else: @@ -1566,7 +1566,7 @@ def visit_FormattedValue(self, n: ast3.FormattedValue) -> Expression: # to allow mypyc to support f-strings with format specifiers and conversions. val_exp = self.visit(n.value) val_exp.set_line(n.lineno, n.col_offset) - conv_str = "" if n.conversion is None or n.conversion < 0 else "!" + chr(n.conversion) # type: ignore[redundant-expr] + conv_str = "" if n.conversion is None or n.conversion < 0 else "!" + chr(n.conversion) format_string = StrExpr("{" + conv_str + ":{}}") format_spec_exp = self.visit(n.format_spec) if n.format_spec is not None else StrExpr("") format_string.set_line(n.lineno, n.col_offset) @@ -2010,10 +2010,10 @@ def visit_Subscript(self, n: ast3.Subscript) -> Type: for s in dims: if getattr(s, "col_offset", None) is None: if isinstance(s, ast3.Index): - s.col_offset = s.value.col_offset + s.col_offset = s.value.col_offset # type: ignore[attr-defined] elif isinstance(s, ast3.Slice): assert s.lower is not None - s.col_offset = s.lower.col_offset + s.col_offset = s.lower.col_offset # type: ignore[attr-defined] sliceval = ast3.Tuple(dims, n.ctx) empty_tuple_index = False From 1bc7b9479092f634435db68a0b311faab56617ac Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Sat, 21 Jan 2023 16:07:48 +0100 Subject: [PATCH 3/6] add explicit use of python 3.7 version in the CONTRIBUTING.md file --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 193c9f27c85b..f7da9aab4eae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,6 +50,8 @@ like this: ``` python3 runtests.py ``` +*Please note that the python version used here is ``3.7``. This is due to the fact that we want to always type check in 3.7 mode to make sure we don't use any features from more recent Python versions.* +*You can change this in the ``mypy_self_check.ini`` file.* You can also use `tox` to run tests (`tox` handles setting up the test environment for you): ``` From b0c2642c124dd1f6aa4bdbbba648fdf245c56d84 Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Sat, 21 Jan 2023 17:11:09 +0100 Subject: [PATCH 4/6] move tomli install into test requirements --- mypy-requirements.txt | 2 +- test-requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy-requirements.txt b/mypy-requirements.txt index a3b51e4f1d32..ee5fe5d295b8 100644 --- a/mypy-requirements.txt +++ b/mypy-requirements.txt @@ -2,4 +2,4 @@ typing_extensions>=3.10 mypy_extensions>=0.4.3 typed_ast>=1.4.0,<2; python_version<'3.8' -tomli>=1.1.0; python_version<'3.12' +tomli>=1.1.0; python_version<'3.11' diff --git a/test-requirements.txt b/test-requirements.txt index ac965f4abc52..548ef9ff5ba0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -17,3 +17,4 @@ pytest-cov>=2.10.0 py>=1.5.2 setuptools>=65.5.1 six +tomli>=1.1.0; python_version<'3.12' From f0db007e08a72ef48de3e16d1ccb0d733f5c5b4b Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Sat, 21 Jan 2023 17:12:16 +0100 Subject: [PATCH 5/6] revert changes in CONTRIBUTING.md --- CONTRIBUTING.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7da9aab4eae..193c9f27c85b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,8 +50,6 @@ like this: ``` python3 runtests.py ``` -*Please note that the python version used here is ``3.7``. This is due to the fact that we want to always type check in 3.7 mode to make sure we don't use any features from more recent Python versions.* -*You can change this in the ``mypy_self_check.ini`` file.* You can also use `tox` to run tests (`tox` handles setting up the test environment for you): ``` From 7908ee751a545d3c9ec70aebd6b3485996b620e2 Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Sun, 22 Jan 2023 16:04:31 +0100 Subject: [PATCH 6/6] remove tomli conditional python version in test_requirements --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index 548ef9ff5ba0..aec11e87e96f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -17,4 +17,4 @@ pytest-cov>=2.10.0 py>=1.5.2 setuptools>=65.5.1 six -tomli>=1.1.0; python_version<'3.12' +tomli>=1.1.0