Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bugs in two of the conformance tests: "generics_basic" and "gen…
…erics_upper_bound". (#1720) These tests attempted to validate that type checkers enforced the rule that constraints and upper bounds within a TypedDict definition cannot be parameterized by other type variables (i.e. cannot be generic). The way the tests were written, they weren't actually testing this check. This allowed mypy and pyre (which both fail to catch this condition) to pass the tests. I've updated the test so it properly tests this condition.
- Loading branch information
Showing
14 changed files
with
149 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
conformant = "Pass" | ||
conformant = "Partial" | ||
notes = """ | ||
Does not reject the use of a constraint parameterized by another type variable. | ||
""" | ||
output = """ | ||
generics_basic.py:36: error: Value of type variable "AnyStr" of "concat" cannot be "Sequence[object]" [type-var] | ||
generics_basic.py:37: error: Value of type variable "AnyStr" of "concat" cannot be "Sequence[object]" [type-var] | ||
generics_basic.py:44: error: TypeVar cannot have only a single constraint [misc] | ||
generics_basic.py:48: error: Type variable "generics_basic.T" is unbound [valid-type] | ||
generics_basic.py:48: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
generics_basic.py:48: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
generics_basic.py:59: error: Value of type variable "AnyStr" of "concat" cannot be "Sequence[object]" [type-var] | ||
generics_basic.py:107: error: Duplicate type variables in Generic[...] or Protocol[...] [misc] | ||
generics_basic.py:140: error: Invalid index type "int" for "MyMap1[str, int]"; expected type "str" [index] | ||
generics_basic.py:141: error: Invalid index type "int" for "MyMap2[int, str]"; expected type "str" [index] | ||
generics_basic.py:167: error: Dynamic metaclass not supported for "GenericMetaInstance" [misc] | ||
generics_basic.py:167: error: Type variable "generics_basic.T" is unbound [valid-type] | ||
generics_basic.py:167: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
generics_basic.py:167: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
generics_basic.py:40: error: Value of type variable "AnyStr" of "concat" cannot be "Sequence[object]" [type-var] | ||
generics_basic.py:41: error: Value of type variable "AnyStr" of "concat" cannot be "Sequence[object]" [type-var] | ||
generics_basic.py:49: error: TypeVar cannot have only a single constraint [misc] | ||
generics_basic.py:69: error: Value of type variable "AnyStr" of "concat" cannot be "Sequence[object]" [type-var] | ||
generics_basic.py:121: error: Duplicate type variables in Generic[...] or Protocol[...] [misc] | ||
generics_basic.py:157: error: Invalid index type "int" for "MyMap1[str, int]"; expected type "str" [index] | ||
generics_basic.py:158: error: Invalid index type "int" for "MyMap2[int, str]"; expected type "str" [index] | ||
generics_basic.py:191: error: Dynamic metaclass not supported for "GenericMetaInstance" [misc] | ||
generics_basic.py:191: error: Type variable "generics_basic.T" is unbound [valid-type] | ||
generics_basic.py:191: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
generics_basic.py:191: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
""" | ||
conformance_automated = "Pass" | ||
conformance_automated = "Fail" | ||
errors_diff = """ | ||
Line 55: Expected 1 errors | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
conformant = "Pass" | ||
conformant = "Partial" | ||
notes = """ | ||
Does not reject use of type variable within an upper bound. | ||
""" | ||
output = """ | ||
generics_upper_bound.py:22: error: Type variable "generics_upper_bound.T" is unbound [valid-type] | ||
generics_upper_bound.py:22: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class) | ||
generics_upper_bound.py:22: note: (Hint: Use "T" in function signature to bind "T" inside a function) | ||
generics_upper_bound.py:41: error: Expression is of type "Collection[int]", not "list[int] | set[int]" [assert-type] | ||
generics_upper_bound.py:48: error: Value of type variable "ST" of "longer" cannot be "int" [type-var] | ||
generics_upper_bound.py:53: error: TypeVar cannot have both values and an upper bound [misc] | ||
generics_upper_bound.py:43: error: Expression is of type "Collection[int]", not "list[int] | set[int]" [assert-type] | ||
generics_upper_bound.py:51: error: Value of type variable "ST" of "longer" cannot be "int" [type-var] | ||
generics_upper_bound.py:56: error: TypeVar cannot have both values and an upper bound [misc] | ||
""" | ||
conformance_automated = "Pass" | ||
conformance_automated = "Fail" | ||
errors_diff = """ | ||
Line 24: Expected 1 errors | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "mypy 1.9.0" | ||
test_duration = 1.6 | ||
test_duration = 1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
False positives in examples using constrained type variables. | ||
False negative for constraint parameterized by a type variable. | ||
False negative in custom map example. | ||
False positive using `iter`. | ||
False negative for generic metaclass. | ||
""" | ||
output = """ | ||
generics_basic.py:31:4 Incompatible return type [7]: Expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`. | ||
generics_basic.py:31:15 Incompatible parameter type [6]: In call `bytes.__add__`, for 1st positional argument, expected `Union[array[typing.Any], bytearray, bytes, _CData, memoryview, mmap, PickleBuffer]` but got `Variable[AnyStr <: [str, bytes]]`. | ||
generics_basic.py:36:14 Incompatible parameter type [6]: In call `concat`, for 2nd positional argument, expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`. | ||
generics_basic.py:37:14 Incompatible parameter type [6]: In call `concat`, for 2nd positional argument, expected `Variable[AnyStr <: [str, bytes]]` but got `str`. | ||
generics_basic.py:44:0 Invalid type [31]: TypeVar can't have a single explicit constraint. Did you mean `bound=str`? | ||
generics_basic.py:48:0 Invalid type [31]: Expression `Variable[BadConstraint2 <: [str, Variable[generics_basic.T]]]` is not a valid type. Type variables cannot contain other type variables in their constraints. | ||
generics_basic.py:59:14 Incompatible parameter type [6]: In call `concat`, for 2nd positional argument, expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`. | ||
generics_basic.py:107:0 Duplicate type variables [59]: Duplicate type variable `T` in Generic[...]. | ||
generics_basic.py:161:25 Undefined attribute [16]: `typing.Iterator` has no attribute `__getitem__`. | ||
generics_basic.py:34:4 Incompatible return type [7]: Expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`. | ||
generics_basic.py:34:15 Incompatible parameter type [6]: In call `bytes.__add__`, for 1st positional argument, expected `Union[array[typing.Any], bytearray, bytes, _CData, memoryview, mmap, PickleBuffer]` but got `Variable[AnyStr <: [str, bytes]]`. | ||
generics_basic.py:40:14 Incompatible parameter type [6]: In call `concat`, for 2nd positional argument, expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`. | ||
generics_basic.py:41:14 Incompatible parameter type [6]: In call `concat`, for 2nd positional argument, expected `Variable[AnyStr <: [str, bytes]]` but got `str`. | ||
generics_basic.py:49:0 Invalid type [31]: TypeVar can't have a single explicit constraint. Did you mean `bound=str`? | ||
generics_basic.py:55:57 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T]]` but got `TypeVar`. | ||
generics_basic.py:69:14 Incompatible parameter type [6]: In call `concat`, for 2nd positional argument, expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`. | ||
generics_basic.py:121:0 Duplicate type variables [59]: Duplicate type variable `T` in Generic[...]. | ||
generics_basic.py:182:25 Undefined attribute [16]: `typing.Iterator` has no attribute `__getitem__`. | ||
""" | ||
conformance_automated = "Fail" | ||
errors_diff = """ | ||
Line 140: Expected 1 errors | ||
Line 141: Expected 1 errors | ||
Line 167: Expected 1 errors | ||
Line 31: Unexpected errors ['generics_basic.py:31:4 Incompatible return type [7]: Expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`.', 'generics_basic.py:31:15 Incompatible parameter type [6]: In call `bytes.__add__`, for 1st positional argument, expected `Union[array[typing.Any], bytearray, bytes, _CData, memoryview, mmap, PickleBuffer]` but got `Variable[AnyStr <: [str, bytes]]`.'] | ||
Line 161: Unexpected errors ['generics_basic.py:161:25 Undefined attribute [16]: `typing.Iterator` has no attribute `__getitem__`.'] | ||
Line 157: Expected 1 errors | ||
Line 158: Expected 1 errors | ||
Line 191: Expected 1 errors | ||
Line 34: Unexpected errors ['generics_basic.py:34:4 Incompatible return type [7]: Expected `Variable[AnyStr <: [str, bytes]]` but got `bytes`.', 'generics_basic.py:34:15 Incompatible parameter type [6]: In call `bytes.__add__`, for 1st positional argument, expected `Union[array[typing.Any], bytearray, bytes, _CData, memoryview, mmap, PickleBuffer]` but got `Variable[AnyStr <: [str, bytes]]`.'] | ||
Line 182: Unexpected errors ['generics_basic.py:182:25 Undefined attribute [16]: `typing.Iterator` has no attribute `__getitem__`.'] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pyre 0.9.19" | ||
test_duration = 4.0 | ||
test_duration = 3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pytype 2024.04.11" | ||
test_duration = 37.5 | ||
test_duration = 35.1 |
Oops, something went wrong.