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
conformance: Fix TypeIs Any intersection case (#2236)
The `assert_type(val, int)` here is incorrect in the negative case
if a type checker is sufficiently precise in its implementation of
intersections.
ty currently infers int & ~Awaitable[object], apparently because it
has chosen to always use the top materialization of TypeIs. A change
I am about to make to pycroscope will have it infer `int | Awaitable[int]`,
because it drops the negated part of Not types.
Copy file name to clipboardExpand all lines: conformance/results/mypy/narrowing_typeis.toml
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
conformant = "Pass"
2
2
output = """
3
-
narrowing_typeis.py:105: error: "TypeIs" functions must have a positional argument [valid-type]
4
3
narrowing_typeis.py:110: error: "TypeIs" functions must have a positional argument [valid-type]
5
-
narrowing_typeis.py:132: error: Argument 1 to "takes_callable_str" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], str]" [arg-type]
6
-
narrowing_typeis.py:152: error: Argument 1 to "takes_callable_str_proto" has incompatible type "Callable[[object], TypeIs[int]]"; expected "CallableStrProto" [arg-type]
7
-
narrowing_typeis.py:152: note: "CallableStrProto.__call__" has type "def __call__(self, val: object) -> str"
8
-
narrowing_typeis.py:169: error: Argument 1 to "takes_typeguard" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], TypeGuard[int]]" [arg-type]
9
-
narrowing_typeis.py:170: error: Argument 1 to "takes_typeis" has incompatible type "Callable[[object], TypeGuard[int]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
10
-
narrowing_typeis.py:191: error: Argument 1 to "takes_int_typeis" has incompatible type "Callable[[object], TypeIs[bool]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
11
-
narrowing_typeis.py:195: error: Narrowed type "str" is not a subtype of input type "int" [narrowed-type-not-subtype]
12
-
narrowing_typeis.py:199: error: Narrowed type "list[int]" is not a subtype of input type "list[object]" [narrowed-type-not-subtype]
4
+
narrowing_typeis.py:115: error: "TypeIs" functions must have a positional argument [valid-type]
5
+
narrowing_typeis.py:137: error: Argument 1 to "takes_callable_str" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], str]" [arg-type]
6
+
narrowing_typeis.py:157: error: Argument 1 to "takes_callable_str_proto" has incompatible type "Callable[[object], TypeIs[int]]"; expected "CallableStrProto" [arg-type]
7
+
narrowing_typeis.py:157: note: "CallableStrProto.__call__" has type "def __call__(self, val: object) -> str"
8
+
narrowing_typeis.py:174: error: Argument 1 to "takes_typeguard" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], TypeGuard[int]]" [arg-type]
9
+
narrowing_typeis.py:175: error: Argument 1 to "takes_typeis" has incompatible type "Callable[[object], TypeGuard[int]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
10
+
narrowing_typeis.py:196: error: Argument 1 to "takes_int_typeis" has incompatible type "Callable[[object], TypeIs[bool]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
11
+
narrowing_typeis.py:200: error: Narrowed type "str" is not a subtype of input type "int" [narrowed-type-not-subtype]
12
+
narrowing_typeis.py:204: error: Narrowed type "list[int]" is not a subtype of input type "list[object]" [narrowed-type-not-subtype]
Copy file name to clipboardExpand all lines: conformance/results/pyrefly/narrowing_typeis.toml
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,13 @@ conformance_automated = "Pass"
3
3
errors_diff = """
4
4
"""
5
5
output = """
6
-
ERROR narrowing_typeis.py:105:9-13: Type guard functions must accept at least one positional argument [bad-function-definition]
7
6
ERROR narrowing_typeis.py:110:9-13: Type guard functions must accept at least one positional argument [bad-function-definition]
8
-
ERROR narrowing_typeis.py:132:20-36: Argument `(val: object) -> TypeIs[int]` is not assignable to parameter `f` with type `(object) -> str` in function `takes_callable_str` [bad-argument-type]
9
-
ERROR narrowing_typeis.py:152:26-42: Argument `(val: object) -> TypeIs[int]` is not assignable to parameter `f` with type `CallableStrProto` in function `takes_callable_str_proto` [bad-argument-type]
10
-
ERROR narrowing_typeis.py:169:17-30: Argument `(val: object) -> TypeIs[int]` is not assignable to parameter `f` with type `(object) -> TypeGuard[int]` in function `takes_typeguard` [bad-argument-type]
11
-
ERROR narrowing_typeis.py:170:14-30: Argument `(val: object) -> TypeGuard[int]` is not assignable to parameter `f` with type `(object) -> TypeIs[int]` in function `takes_typeis` [bad-argument-type]
12
-
ERROR narrowing_typeis.py:191:18-29: Argument `(val: object) -> TypeIs[bool]` is not assignable to parameter `f` with type `(object) -> TypeIs[int]` in function `takes_int_typeis` [bad-argument-type]
13
-
ERROR narrowing_typeis.py:195:5-15: Return type `str` must be assignable to the first argument type `int` [bad-function-definition]
14
-
ERROR narrowing_typeis.py:199:5-24: Return type `list[int]` must be assignable to the first argument type `list[object]` [bad-function-definition]
7
+
ERROR narrowing_typeis.py:115:9-13: Type guard functions must accept at least one positional argument [bad-function-definition]
8
+
ERROR narrowing_typeis.py:137:20-36: Argument `(val: object) -> TypeIs[int]` is not assignable to parameter `f` with type `(object) -> str` in function `takes_callable_str` [bad-argument-type]
9
+
ERROR narrowing_typeis.py:157:26-42: Argument `(val: object) -> TypeIs[int]` is not assignable to parameter `f` with type `CallableStrProto` in function `takes_callable_str_proto` [bad-argument-type]
10
+
ERROR narrowing_typeis.py:174:17-30: Argument `(val: object) -> TypeIs[int]` is not assignable to parameter `f` with type `(object) -> TypeGuard[int]` in function `takes_typeguard` [bad-argument-type]
11
+
ERROR narrowing_typeis.py:175:14-30: Argument `(val: object) -> TypeGuard[int]` is not assignable to parameter `f` with type `(object) -> TypeIs[int]` in function `takes_typeis` [bad-argument-type]
12
+
ERROR narrowing_typeis.py:196:18-29: Argument `(val: object) -> TypeIs[bool]` is not assignable to parameter `f` with type `(object) -> TypeIs[int]` in function `takes_int_typeis` [bad-argument-type]
13
+
ERROR narrowing_typeis.py:200:5-15: Return type `str` must be assignable to the first argument type `int` [bad-function-definition]
14
+
ERROR narrowing_typeis.py:204:5-24: Return type `list[int]` must be assignable to the first argument type `list[object]` [bad-function-definition]
Copy file name to clipboardExpand all lines: conformance/results/pyright/narrowing_typeis.toml
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,34 +3,34 @@ conformance_automated = "Pass"
3
3
errors_diff = """
4
4
"""
5
5
output = """
6
-
narrowing_typeis.py:105:9 - error: User-defined type guard functions and methods must have at least one input parameter (reportGeneralTypeIssues)
7
6
narrowing_typeis.py:110:9 - error: User-defined type guard functions and methods must have at least one input parameter (reportGeneralTypeIssues)
8
-
narrowing_typeis.py:132:20 - error: Argument of type "(val: object) -> TypeIs[int]" cannot be assigned to parameter "f" of type "(object) -> str" in function "takes_callable_str"
7
+
narrowing_typeis.py:115:9 - error: User-defined type guard functions and methods must have at least one input parameter (reportGeneralTypeIssues)
8
+
narrowing_typeis.py:137:20 - error: Argument of type "(val: object) -> TypeIs[int]" cannot be assigned to parameter "f" of type "(object) -> str" in function "takes_callable_str"
9
9
Type "(val: object) -> TypeIs[int]" is not assignable to type "(object) -> str"
10
10
Function return type "TypeIs[int]" is incompatible with type "str"
11
11
"TypeIs[int]" is not assignable to "str"
12
12
"bool" is not assignable to "str" (reportArgumentType)
13
-
narrowing_typeis.py:152:26 - error: Argument of type "(val: object) -> TypeIs[int]" cannot be assigned to parameter "f" of type "CallableStrProto" in function "takes_callable_str_proto"
13
+
narrowing_typeis.py:157:26 - error: Argument of type "(val: object) -> TypeIs[int]" cannot be assigned to parameter "f" of type "CallableStrProto" in function "takes_callable_str_proto"
14
14
Type "(val: object) -> TypeIs[int]" is not assignable to type "(val: object) -> str"
15
15
Function return type "TypeIs[int]" is incompatible with type "str"
16
16
"TypeIs[int]" is not assignable to "str"
17
17
"bool" is not assignable to "str" (reportArgumentType)
18
-
narrowing_typeis.py:169:17 - error: Argument of type "(val: object) -> TypeIs[int]" cannot be assigned to parameter "f" of type "(object) -> TypeGuard[int]" in function "takes_typeguard"
18
+
narrowing_typeis.py:174:17 - error: Argument of type "(val: object) -> TypeIs[int]" cannot be assigned to parameter "f" of type "(object) -> TypeGuard[int]" in function "takes_typeguard"
19
19
Type "(val: object) -> TypeIs[int]" is not assignable to type "(object) -> TypeGuard[int]"
20
20
Function return type "TypeIs[int]" is incompatible with type "TypeGuard[int]"
21
21
"TypeIs[int]" is not assignable to "TypeGuard[int]"
22
22
"bool" is not assignable to "TypeGuard[int]" (reportArgumentType)
23
-
narrowing_typeis.py:170:14 - error: Argument of type "(val: object) -> TypeGuard[int]" cannot be assigned to parameter "f" of type "(object) -> TypeIs[int]" in function "takes_typeis"
23
+
narrowing_typeis.py:175:14 - error: Argument of type "(val: object) -> TypeGuard[int]" cannot be assigned to parameter "f" of type "(object) -> TypeIs[int]" in function "takes_typeis"
24
24
Type "(val: object) -> TypeGuard[int]" is not assignable to type "(object) -> TypeIs[int]"
25
25
Function return type "TypeGuard[int]" is incompatible with type "TypeIs[int]"
26
26
"TypeGuard[int]" is not assignable to "TypeIs[int]"
27
27
"bool" is not assignable to "TypeIs[int]" (reportArgumentType)
28
-
narrowing_typeis.py:191:18 - error: Argument of type "(val: object) -> TypeIs[bool]" cannot be assigned to parameter "f" of type "(object) -> TypeIs[int]" in function "takes_int_typeis"
28
+
narrowing_typeis.py:196:18 - error: Argument of type "(val: object) -> TypeIs[bool]" cannot be assigned to parameter "f" of type "(object) -> TypeIs[int]" in function "takes_int_typeis"
29
29
Type "(val: object) -> TypeIs[bool]" is not assignable to type "(object) -> TypeIs[int]"
30
30
Function return type "TypeIs[bool]" is incompatible with type "TypeIs[int]"
31
31
"TypeIs[bool]" is not assignable to "TypeIs[int]"
32
32
Type parameter "T@TypeIs" is invariant, but "bool" is not the same as "int"
33
33
"bool" is not assignable to "TypeIs[int]" (reportArgumentType)
34
-
narrowing_typeis.py:195:27 - error: Return type of TypeIs ("str") is not consistent with value parameter type ("int") (reportGeneralTypeIssues)
35
-
narrowing_typeis.py:199:45 - error: Return type of TypeIs ("list[int]") is not consistent with value parameter type ("list[object]") (reportGeneralTypeIssues)
34
+
narrowing_typeis.py:200:27 - error: Return type of TypeIs ("str") is not consistent with value parameter type ("int") (reportGeneralTypeIssues)
35
+
narrowing_typeis.py:204:45 - error: Return type of TypeIs ("list[int]") is not consistent with value parameter type ("list[object]") (reportGeneralTypeIssues)
Copy file name to clipboardExpand all lines: conformance/results/ty/narrowing_typeis.toml
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,13 @@ Line 35: Unexpected errors ['narrowing_typeis.py:35:18: error[invalid-assignment
8
8
"""
9
9
output = """
10
10
narrowing_typeis.py:35:18: error[invalid-assignment] Object of type `object` is not assignable to `int`
11
-
narrowing_typeis.py:105:23: error[invalid-type-guard-definition] `TypeIs` function must have a parameter to narrow
12
-
narrowing_typeis.py:110:22: error[invalid-type-guard-definition] `TypeIs` function must have a parameter to narrow
13
-
narrowing_typeis.py:132:20: error[invalid-argument-type] Argument to function `takes_callable_str` is incorrect: Expected `(object, /) -> str`, found `def simple_typeguard(val: object) -> TypeIs[int]`
14
-
narrowing_typeis.py:152:26: error[invalid-argument-type] Argument to function `takes_callable_str_proto` is incorrect: Expected `CallableStrProto`, found `def simple_typeguard(val: object) -> TypeIs[int]`
15
-
narrowing_typeis.py:169:17: error[invalid-argument-type] Argument to function `takes_typeguard` is incorrect: Expected `(object, /) -> TypeGuard[int]`, found `def is_int_typeis(val: object) -> TypeIs[int]`
16
-
narrowing_typeis.py:170:14: error[invalid-argument-type] Argument to function `takes_typeis` is incorrect: Expected `(object, /) -> TypeIs[int]`, found `def is_int_typeguard(val: object) -> TypeGuard[int]`
17
-
narrowing_typeis.py:191:18: error[invalid-argument-type] Argument to function `takes_int_typeis` is incorrect: Expected `(object, /) -> TypeIs[int]`, found `def bool_typeis(val: object) -> TypeIs[bool]`
18
-
narrowing_typeis.py:195:27: error[invalid-type-guard-definition] Narrowed type `str` is not assignable to the declared parameter type `int`
19
-
narrowing_typeis.py:199:45: error[invalid-type-guard-definition] Narrowed type `list[int]` is not assignable to the declared parameter type `list[object]`
11
+
narrowing_typeis.py:110:23: error[invalid-type-guard-definition] `TypeIs` function must have a parameter to narrow
12
+
narrowing_typeis.py:115:22: error[invalid-type-guard-definition] `TypeIs` function must have a parameter to narrow
13
+
narrowing_typeis.py:137:20: error[invalid-argument-type] Argument to function `takes_callable_str` is incorrect: Expected `(object, /) -> str`, found `def simple_typeguard(val: object) -> TypeIs[int]`
14
+
narrowing_typeis.py:157:26: error[invalid-argument-type] Argument to function `takes_callable_str_proto` is incorrect: Expected `CallableStrProto`, found `def simple_typeguard(val: object) -> TypeIs[int]`
15
+
narrowing_typeis.py:174:17: error[invalid-argument-type] Argument to function `takes_typeguard` is incorrect: Expected `(object, /) -> TypeGuard[int]`, found `def is_int_typeis(val: object) -> TypeIs[int]`
16
+
narrowing_typeis.py:175:14: error[invalid-argument-type] Argument to function `takes_typeis` is incorrect: Expected `(object, /) -> TypeIs[int]`, found `def is_int_typeguard(val: object) -> TypeGuard[int]`
17
+
narrowing_typeis.py:196:18: error[invalid-argument-type] Argument to function `takes_int_typeis` is incorrect: Expected `(object, /) -> TypeIs[int]`, found `def bool_typeis(val: object) -> TypeIs[bool]`
18
+
narrowing_typeis.py:200:27: error[invalid-type-guard-definition] Narrowed type `str` is not assignable to the declared parameter type `int`
19
+
narrowing_typeis.py:204:45: error[invalid-type-guard-definition] Narrowed type `list[int]` is not assignable to the declared parameter type `list[object]`
Copy file name to clipboardExpand all lines: conformance/results/zuban/narrowing_typeis.toml
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@ conformance_automated = "Pass"
2
2
errors_diff = """
3
3
"""
4
4
output = """
5
-
narrowing_typeis.py:105: error: "TypeIs" functions must have a positional argument [misc]
6
5
narrowing_typeis.py:110: error: "TypeIs" functions must have a positional argument [misc]
7
-
narrowing_typeis.py:132: error: Argument 1 to "takes_callable_str" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], str]" [arg-type]
8
-
narrowing_typeis.py:152: error: Argument 1 to "takes_callable_str_proto" has incompatible type "Callable[[object], TypeIs[int]]"; expected "CallableStrProto" [arg-type]
9
-
narrowing_typeis.py:169: error: Argument 1 to "takes_typeguard" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], TypeGuard[int]]" [arg-type]
10
-
narrowing_typeis.py:170: error: Argument 1 to "takes_typeis" has incompatible type "Callable[[object], TypeGuard[int]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
11
-
narrowing_typeis.py:191: error: Argument 1 to "takes_int_typeis" has incompatible type "Callable[[object], TypeIs[bool]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
12
-
narrowing_typeis.py:195: error: Narrowed type "str" is not a subtype of input type "int" [narrowed-type-not-subtype]
13
-
narrowing_typeis.py:199: error: Narrowed type "list[int]" is not a subtype of input type "list[object]" [narrowed-type-not-subtype]
6
+
narrowing_typeis.py:115: error: "TypeIs" functions must have a positional argument [misc]
7
+
narrowing_typeis.py:137: error: Argument 1 to "takes_callable_str" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], str]" [arg-type]
8
+
narrowing_typeis.py:157: error: Argument 1 to "takes_callable_str_proto" has incompatible type "Callable[[object], TypeIs[int]]"; expected "CallableStrProto" [arg-type]
9
+
narrowing_typeis.py:174: error: Argument 1 to "takes_typeguard" has incompatible type "Callable[[object], TypeIs[int]]"; expected "Callable[[object], TypeGuard[int]]" [arg-type]
10
+
narrowing_typeis.py:175: error: Argument 1 to "takes_typeis" has incompatible type "Callable[[object], TypeGuard[int]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
11
+
narrowing_typeis.py:196: error: Argument 1 to "takes_int_typeis" has incompatible type "Callable[[object], TypeIs[bool]]"; expected "Callable[[object], TypeIs[int]]" [arg-type]
12
+
narrowing_typeis.py:200: error: Narrowed type "str" is not a subtype of input type "int" [narrowed-type-not-subtype]
13
+
narrowing_typeis.py:204: error: Narrowed type "list[int]" is not a subtype of input type "list[object]" [narrowed-type-not-subtype]
0 commit comments