You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#7846
The fix is mostly straightforward, instead of ad-hoc guessing of type variables from the return type, we pass the them all the way through intermediate helper functions.
The `ctypes` plugin change is because it used the bare representation of types (the one used by `reveal_type()`) for user errors. So after my change arrangement of stars changed, instead of adjusting it, I switched to the proper type formatting.
Copy file name to clipboardExpand all lines: test-data/unit/check-ctypes.test
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,8 @@ class MyCInt(ctypes.c_int):
6
6
7
7
intarr4 = ctypes.c_int * 4
8
8
a = intarr4(1, ctypes.c_int(2), MyCInt(3), 4)
9
-
intarr4(1, 2, 3, "invalid") # E: Array constructor argument 4 of type "builtins.str" is not convertible to the array element type "ctypes.c_int"
10
-
reveal_type(a) # N: Revealed type is 'ctypes.Array[ctypes.c_int]'
9
+
intarr4(1, 2, 3, "invalid") # E: Array constructor argument 4 of type "str" is not convertible to the array element type "c_int"
10
+
reveal_type(a) # N: Revealed type is 'ctypes.Array[ctypes.c_int*]'
11
11
reveal_type(a[0]) # N: Revealed type is 'builtins.int'
12
12
reveal_type(a[1:3]) # N: Revealed type is 'builtins.list[builtins.int]'
13
13
a[0] = 42
@@ -30,11 +30,11 @@ class MyCInt(ctypes.c_int):
30
30
31
31
myintarr4 = MyCInt * 4
32
32
mya = myintarr4(1, 2, MyCInt(3), 4)
33
-
myintarr4(1, ctypes.c_int(2), MyCInt(3), "invalid") # E: Array constructor argument 2 of type "ctypes.c_int" is not convertible to the array element type "__main__.MyCInt" \
34
-
# E: Array constructor argument 4 of type "builtins.str" is not convertible to the array element type "__main__.MyCInt"
35
-
reveal_type(mya) # N: Revealed type is 'ctypes.Array[__main__.MyCInt]'
36
-
reveal_type(mya[0]) # N: Revealed type is '__main__.MyCInt'
37
-
reveal_type(mya[1:3]) # N: Revealed type is 'builtins.list[__main__.MyCInt]'
33
+
myintarr4(1, ctypes.c_int(2), MyCInt(3), "invalid") # E: Array constructor argument 2 of type "c_int" is not convertible to the array element type "MyCInt" \
34
+
# E: Array constructor argument 4 of type "str" is not convertible to the array element type "MyCInt"
35
+
reveal_type(mya) # N: Revealed type is 'ctypes.Array[__main__.MyCInt*]'
36
+
reveal_type(mya[0]) # N: Revealed type is '__main__.MyCInt*'
37
+
reveal_type(mya[1:3]) # N: Revealed type is 'builtins.list[__main__.MyCInt*]'
38
38
mya[0] = 42
39
39
mya[1] = ctypes.c_int(42) # E: No overload variant of "__setitem__" of "Array" matches argument types "int", "c_int" \
40
40
# N: Possible overload variants: \
@@ -106,7 +106,7 @@ import ctypes
106
106
107
107
wca = (ctypes.c_wchar * 4)('a', 'b', 'c', '\x00')
108
108
reveal_type(wca.value) # N: Revealed type is 'builtins.str'
109
-
wca.raw # E: ctypes.Array attribute "raw" is only available with element type c_char, not "ctypes.c_wchar"
109
+
wca.raw # E: Array attribute "raw" is only available with element type "c_char", not "c_wchar"
reveal_type(intarr4(*int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]'
172
-
reveal_type(intarr4(*c_int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]'
173
-
reveal_type(intarr6(1, ctypes.c_int(2), *int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]'
174
-
reveal_type(intarr6(1, ctypes.c_int(2), *c_int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int]'
171
+
reveal_type(intarr4(*int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int*]'
172
+
reveal_type(intarr4(*c_int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int*]'
173
+
reveal_type(intarr6(1, ctypes.c_int(2), *int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int*]'
174
+
reveal_type(intarr6(1, ctypes.c_int(2), *c_int_values)) # N: Revealed type is 'ctypes.Array[ctypes.c_int*]'
175
175
176
176
float_values = [1.0, 2.0, 3.0, 4.0]
177
-
intarr4(*float_values) # E: Array constructor argument 1 of type "builtins.list[builtins.float*]" is not convertible to the array element type "Iterable[ctypes.c_int]"
177
+
intarr4(*float_values) # E: Array constructor argument 1 of type "List[float]" is not convertible to the array element type "Iterable[c_int]"
0 commit comments