summaryrefslogtreecommitdiff
blob: a7a581ea896980052b935e3aaa1a812f4116413e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
From 13ae58ffe8bedb7da9f4c657297f0d61e681d671 Mon Sep 17 00:00:00 2001
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Date: Sun, 30 Aug 2020 18:11:57 -0700
Subject: [PATCH] mypy: get CI green for py39 (#9376)

Due to Python 3.9's new parser, this has a different (and better) error
message on Python 3.9.

This is effectively a test of typed_ast / ast, so I don't think it
matters too much. I'm happy to alternatively just get rid of the test
altogether, or if people feel strongly, come up with a way to run the
test when run with older Pythons.

Co-authored-by: hauntsaninja <>
---
 .travis.yml                        | 3 ---
 mypy/test/testcheck.py             | 2 ++
 test-data/unit/check-kwargs.test   | 7 -------
 test-data/unit/check-python39.test | 9 +++++++++
 4 files changed, 11 insertions(+), 10 deletions(-)
 create mode 100644 test-data/unit/check-python39.test

diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py
index 49a85861b6..39a35c7280 100644
--- a/mypy/test/testcheck.py
+++ b/mypy/test/testcheck.py
@@ -94,6 +94,8 @@
 # Tests that use Python 3.8-only AST features (like expression-scoped ignores):
 if sys.version_info >= (3, 8):
     typecheck_files.append('check-python38.test')
+if sys.version_info >= (3, 9):
+    typecheck_files.append('check-python39.test')
 
 # Special tests for platforms with case-insensitive filesystems.
 if sys.platform in ('darwin', 'win32'):
diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test
index 1dd450caae..a587be3e06 100644
--- a/test-data/unit/check-kwargs.test
+++ b/test-data/unit/check-kwargs.test
@@ -53,13 +53,6 @@ f(b=[], a=A())
 class A: pass
 [builtins fixtures/list.pyi]
 
-[case testGivingSameKeywordArgumentTwice]
-import typing
-def f(a: 'A', b: 'B') -> None: pass
-f(a=A(), b=B(), a=A()) # E: keyword argument repeated
-class A: pass
-class B: pass
-
 [case testGivingArgumentAsPositionalAndKeywordArg]
 import typing
 def f(a: 'A', b: 'B' = None) -> None: pass
diff --git a/test-data/unit/check-python39.test b/test-data/unit/check-python39.test
new file mode 100644
index 0000000000..0e9ec683ae
--- /dev/null
+++ b/test-data/unit/check-python39.test
@@ -0,0 +1,9 @@
+[case testGivingSameKeywordArgumentTwice]
+# This test was originally in check-kwargs.test
+# Python 3.9's new parser started producing a different error message here. Since this isn't the
+# most important test, to deal with this we'll only run this test with Python 3.9 and later.
+import typing
+def f(a: 'A', b: 'B') -> None: pass
+f(a=A(), b=B(), a=A()) # E: "f" gets multiple values for keyword argument "a"
+class A: pass
+class B: pass
From ab1bd98cc8a6415398121a47c687ede6f4cca4fd Mon Sep 17 00:00:00 2001
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Date: Thu, 8 Oct 2020 11:18:18 -0700
Subject: [PATCH] py39: fix mypyc complaint (#9552)

I was trying to build wheels for Python 3.9 as part of #9536, but ran
into this issue. You'll notice a couple hundred lines up msullivan
points out that mypyc can't handle conditional method definition, so
that's not an option here.

Co-authored-by: hauntsaninja <>
---
 mypy/fastparse.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mypy/fastparse.py b/mypy/fastparse.py
index 2dafbf4e14..0b72214100 100644
--- a/mypy/fastparse.py
+++ b/mypy/fastparse.py
@@ -1257,11 +1257,13 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
 
     # ExtSlice(slice* dims)
     def visit_ExtSlice(self, n: ast3.ExtSlice) -> TupleExpr:
-        return TupleExpr(self.translate_expr_list(n.dims))
+        # cast for mypyc's benefit on Python 3.9
+        return TupleExpr(self.translate_expr_list(cast(Any, n.dims)))
 
     # Index(expr value)
     def visit_Index(self, n: Index) -> Node:
-        return self.visit(n.value)
+        # cast for mypyc's benefit on Python 3.9
+        return self.visit(cast(Any, n.value))
 
 
 class TypeConverter:
From ffed88fb95fcbfdd1363f0f719bd3e13f8fe20e9 Mon Sep 17 00:00:00 2001
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Date: Thu, 8 Oct 2020 15:00:42 -0700
Subject: [PATCH] py39: fix mypyc complaints part 2 (#9562)

Necessary because I previously didn't actually fix mypyc's complaint +
mypyc has more complaints.
The sys.version_info aliasing works around us hitting
https://github.com/python/mypy/blob/08f207ef4a09f56d710d63775771ae921c41d4bc/mypyc/irbuild/expression.py#L44

Co-authored-by: hauntsaninja <>
---
 mypy/fastparse.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/mypy/fastparse.py b/mypy/fastparse.py
index 0b72214100..3319cd6489 100644
--- a/mypy/fastparse.py
+++ b/mypy/fastparse.py
@@ -169,7 +169,9 @@ def parse(source: Union[str, bytes],
         tree.path = fnam
         tree.is_stub = is_stub_file
     except SyntaxError as e:
-        if sys.version_info < (3, 9) and e.filename == "<fstring>":
+        # alias to please mypyc
+        is_py38_or_earlier = sys.version_info < (3, 9)
+        if is_py38_or_earlier and e.filename == "<fstring>":
             # In Python 3.8 and earlier, syntax errors in f-strings have lineno relative to the
             # start of the f-string. This would be misleading, as mypy will report the error as the
             # lineno within the file.
@@ -1210,9 +1212,11 @@ def visit_Attribute(self, n: Attribute) -> Union[MemberExpr, SuperExpr]:
     def visit_Subscript(self, n: ast3.Subscript) -> IndexExpr:
         e = IndexExpr(self.visit(n.value), self.visit(n.slice))
         self.set_line(e, n)
+        # alias to please mypyc
+        is_py38_or_earlier = sys.version_info < (3, 9)
         if (
             isinstance(n.slice, ast3.Slice) or
-            (sys.version_info < (3, 9) and isinstance(n.slice, ast3.ExtSlice))
+            (is_py38_or_earlier and isinstance(n.slice, ast3.ExtSlice))
         ):
             # Before Python 3.9, Slice has no line/column in the raw ast. To avoid incompatibility
             # visit_Slice doesn't set_line, even in Python 3.9 on.
@@ -1258,12 +1262,12 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
     # ExtSlice(slice* dims)
     def visit_ExtSlice(self, n: ast3.ExtSlice) -> TupleExpr:
         # cast for mypyc's benefit on Python 3.9
-        return TupleExpr(self.translate_expr_list(cast(Any, n.dims)))
+        return TupleExpr(self.translate_expr_list(cast(Any, n).dims))
 
     # Index(expr value)
     def visit_Index(self, n: Index) -> Node:
         # cast for mypyc's benefit on Python 3.9
-        return self.visit(cast(Any, n.value))
+        return self.visit(cast(Any, n).value)
 
 
 class TypeConverter: