Skip to content

Commit

Permalink
Added missing tests for "TypeVar with upper bounds" section of Generi… (
Browse files Browse the repository at this point in the history
#1662)

Added missing tests for "TypeVar with upper bounds" section of Generics chapter.
  • Loading branch information
erictraut authored Mar 16, 2024
1 parent fb1ca3a commit 1006bed
Show file tree
Hide file tree
Showing 52 changed files with 622 additions and 16 deletions.
22 changes: 22 additions & 0 deletions conformance/results/mypy/aliases_explicit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,26 @@ notes = """
Does not reject specialization of type alias that has already been implicitly specialized.
"""
output = """
aliases_explicit.py:67: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
aliases_explicit.py:68: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
aliases_explicit.py:69: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
aliases_explicit.py:70: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
aliases_explicit.py:71: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int" [misc]
aliases_explicit.py:79: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:80: error: Bracketed expression "[...]" is not valid as a type [valid-type]
aliases_explicit.py:81: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:82: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:83: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:84: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:85: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:86: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:87: error: Variable "aliases_explicit.var1" is not valid as a type [valid-type]
aliases_explicit.py:87: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_explicit.py:88: error: Invalid type: try using Literal[True] instead? [valid-type]
aliases_explicit.py:89: error: Invalid type: try using Literal[1] instead? [valid-type]
aliases_explicit.py:90: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:90: error: Function "list" could always be true in boolean context [truthy-function]
aliases_explicit.py:91: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:101: error: "<typing special form>" not callable [operator]
aliases_explicit.py:102: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
"""
37 changes: 37 additions & 0 deletions conformance/results/mypy/aliases_implicit.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
conformant = "Pass"
output = """
aliases_implicit.py:76: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
aliases_implicit.py:77: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
aliases_implicit.py:78: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
aliases_implicit.py:79: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
aliases_implicit.py:80: error: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int" [misc]
aliases_implicit.py:81: error: Type argument "str" of "GoodTypeAlias12" must be a subtype of "float" [type-var]
aliases_implicit.py:100: error: Function "list" could always be true in boolean context [truthy-function]
aliases_implicit.py:106: error: Variable "aliases_implicit.BadTypeAlias1" is not valid as a type [valid-type]
aliases_implicit.py:106: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:107: error: Variable "aliases_implicit.BadTypeAlias2" is not valid as a type [valid-type]
aliases_implicit.py:107: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:108: error: Variable "aliases_implicit.BadTypeAlias3" is not valid as a type [valid-type]
aliases_implicit.py:108: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:109: error: Variable "aliases_implicit.BadTypeAlias4" is not valid as a type [valid-type]
aliases_implicit.py:109: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:110: error: Variable "aliases_implicit.BadTypeAlias5" is not valid as a type [valid-type]
aliases_implicit.py:110: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:111: error: Variable "aliases_implicit.BadTypeAlias6" is not valid as a type [valid-type]
aliases_implicit.py:111: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:112: error: Variable "aliases_implicit.BadTypeAlias7" is not valid as a type [valid-type]
aliases_implicit.py:112: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:113: error: Variable "aliases_implicit.BadTypeAlias8" is not valid as a type [valid-type]
aliases_implicit.py:113: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:114: error: Variable "aliases_implicit.BadTypeAlias9" is not valid as a type [valid-type]
aliases_implicit.py:114: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:115: error: Variable "aliases_implicit.BadTypeAlias10" is not valid as a type [valid-type]
aliases_implicit.py:115: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:116: error: Variable "aliases_implicit.BadTypeAlias11" is not valid as a type [valid-type]
aliases_implicit.py:116: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:117: error: Variable "aliases_implicit.BadTypeAlias12" is not valid as a type [valid-type]
aliases_implicit.py:117: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:118: error: Variable "aliases_implicit.BadTypeAlias13" is not valid as a type [valid-type]
aliases_implicit.py:118: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:119: error: Variable "aliases_implicit.BadTypeAlias14" is not valid as a type [valid-type]
aliases_implicit.py:119: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_implicit.py:133: error: "<typing special form>" not callable [operator]
aliases_implicit.py:135: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
"""
17 changes: 17 additions & 0 deletions conformance/results/mypy/aliases_newtype.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
conformant = "Pass"
output = """
aliases_newtype.py:11: error: Argument 1 to "UserId" has incompatible type "str"; expected "int" [arg-type]
aliases_newtype.py:12: error: Incompatible types in assignment (expression has type "int", variable has type "UserId") [assignment]
aliases_newtype.py:20: error: Cannot use isinstance() with NewType type [misc]
aliases_newtype.py:23: error: Cannot subclass "NewType" [misc]
aliases_newtype.py:32: error: String argument 1 "BadName" to NewType(...) does not match variable name "GoodName" [misc]
aliases_newtype.py:38: error: "GoodNewType1" expects no type arguments, but 1 given [type-arg]
aliases_newtype.py:41: error: Cannot redefine "GoodNewType2" as a NewType [misc]
aliases_newtype.py:41: error: Name "GoodNewType2" already defined on line 36 [no-redef]
aliases_newtype.py:44: error: Argument 2 to NewType(...) must be subclassable (got "int | str") [valid-newtype]
aliases_newtype.py:47: error: Type variable "aliases_newtype.T" is unbound [valid-type]
aliases_newtype.py:47: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
aliases_newtype.py:47: note: (Hint: Use "T" in function signature to bind "T" inside a function)
aliases_newtype.py:49: error: NewType cannot be used with protocol classes [misc]
aliases_newtype.py:51: error: Argument 2 to NewType(...) must be subclassable (got "Literal[7]") [valid-newtype]
aliases_newtype.py:58: error: Argument 2 to NewType(...) must be subclassable (got "TD1") [valid-newtype]
aliases_newtype.py:60: error: NewType(...) expects exactly two positional arguments [misc]
aliases_newtype.py:62: error: Argument 2 to NewType(...) must be subclassable (got "Any") [valid-newtype]
"""
11 changes: 11 additions & 0 deletions conformance/results/mypy/aliases_recursive.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
conformant = "Pass"
output = """
aliases_recursive.py:19: error: Dict entry 1 has incompatible type "str": "complex"; expected "str": "int | str | float | list[Json] | dict[str, Json] | None" [dict-item]
aliases_recursive.py:20: error: List item 1 has incompatible type "complex"; expected "int | str | float | list[Json] | dict[str, Json] | None" [list-item]
aliases_recursive.py:38: error: Incompatible types in assignment (expression has type "tuple[int, tuple[str, int], tuple[int, tuple[int, list[int]]]]", variable has type "RecursiveTuple") [assignment]
aliases_recursive.py:39: error: Name "t6" already defined on line 38 [no-redef]
aliases_recursive.py:50: error: Dict entry 0 has incompatible type "str": "list[int]"; expected "str": "str | int | Mapping[str, RecursiveMapping]" [dict-item]
aliases_recursive.py:51: error: Dict entry 2 has incompatible type "str": "list[int]"; expected "str": "str | int | Mapping[str, RecursiveMapping]" [dict-item]
aliases_recursive.py:55: error: Dict entry 2 has incompatible type "str": "list[int]"; expected "str": "str | int | Mapping[str, RecursiveMapping]" [dict-item]
aliases_recursive.py:67: error: List item 0 has incompatible type "float"; expected "GenericTypeAlias1[str] | str" [list-item]
aliases_recursive.py:73: error: List item 0 has incompatible type "float"; expected "GenericTypeAlias2[str, int] | str | int" [list-item]
aliases_recursive.py:76: error: Invalid recursive alias: a union item of itself [misc]
aliases_recursive.py:81: error: Invalid recursive alias: a union item of itself [misc]
"""
41 changes: 41 additions & 0 deletions conformance/results/mypy/aliases_type_statement.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ notes = """
Does not support `type` statement.
"""
output = """
aliases_type_statement.py: error: Cannot assign multiple types to name "BadTypeAlias14" without an explicit "Type[...]" annotation [misc]
aliases_type_statement.py:8: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:9: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:9: error: Name "S3" is not defined [name-defined]
aliases_type_statement.py:9: error: Name "S1" is not defined [name-defined]
aliases_type_statement.py:9: error: Name "S2" is not defined [name-defined]
aliases_type_statement.py:10: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:10: error: Value of type "UnionType" is not indexable [index]
aliases_type_statement.py:14: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:21: error: "type[int]" has no attribute "__value__" [attr-defined]
aliases_type_statement.py:23: error: "type[int]" has no attribute "other_attrib" [attr-defined]
aliases_type_statement.py:37: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:38: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:39: error: PEP 695 type aliases are not yet supported [valid-type]
Expand All @@ -19,17 +26,51 @@ aliases_type_statement.py:45: error: PEP 695 type aliases are not yet supported
aliases_type_statement.py:46: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:47: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:48: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:48: error: Function "list" could always be true in boolean context [truthy-function]
aliases_type_statement.py:49: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:52: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:54: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:58: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:64: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:64: error: Name "K" is not defined [name-defined]
aliases_type_statement.py:69: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:72: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:72: error: Name "T" is not defined [name-defined]
aliases_type_statement.py:72: error: Variable "aliases_type_statement.RecursiveTypeAlias1" is not valid as a type [valid-type]
aliases_type_statement.py:72: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:74: error: Variable "aliases_type_statement.RecursiveTypeAlias1" is not valid as a type [valid-type]
aliases_type_statement.py:74: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:75: error: Variable "aliases_type_statement.RecursiveTypeAlias1" is not valid as a type [valid-type]
aliases_type_statement.py:75: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:77: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:77: error: Name "P" is not defined [name-defined]
aliases_type_statement.py:77: error: Name "T" is not defined [name-defined]
aliases_type_statement.py:77: error: Name "S" is not defined [name-defined]
aliases_type_statement.py:77: error: Variable "aliases_type_statement.RecursiveTypeAlias2" is not valid as a type [valid-type]
aliases_type_statement.py:77: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:79: error: Unexpected "..." [misc]
aliases_type_statement.py:79: error: Variable "aliases_type_statement.RecursiveTypeAlias2" is not valid as a type [valid-type]
aliases_type_statement.py:79: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:80: error: Unexpected "..." [misc]
aliases_type_statement.py:80: error: Variable "aliases_type_statement.RecursiveTypeAlias2" is not valid as a type [valid-type]
aliases_type_statement.py:80: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:81: error: Unexpected "..." [misc]
aliases_type_statement.py:81: error: Variable "aliases_type_statement.RecursiveTypeAlias2" is not valid as a type [valid-type]
aliases_type_statement.py:81: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:82: error: Bracketed expression "[...]" is not valid as a type [valid-type]
aliases_type_statement.py:82: error: Variable "aliases_type_statement.RecursiveTypeAlias2" is not valid as a type [valid-type]
aliases_type_statement.py:82: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:84: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:84: error: Name "RecursiveTypeAlias3" is not defined [name-defined]
aliases_type_statement.py:86: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:86: error: Name "T" is not defined [name-defined]
aliases_type_statement.py:86: error: Cannot determine type of "RecursiveTypeAlias4" [has-type]
aliases_type_statement.py:88: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:88: error: Name "T" is not defined [name-defined]
aliases_type_statement.py:88: error: Variable "aliases_type_statement.RecursiveTypeAlias5" is not valid as a type [valid-type]
aliases_type_statement.py:88: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
aliases_type_statement.py:90: error: PEP 695 type aliases are not yet supported [valid-type]
aliases_type_statement.py:90: error: Cannot resolve name "RecursiveTypeAlias7" (possible cyclic definition) [misc]
aliases_type_statement.py:90: error: Name "RecursiveTypeAlias7" is used before definition [used-before-def]
aliases_type_statement.py:91: error: PEP 695 type aliases are not yet supported [valid-type]
"""
Loading

0 comments on commit 1006bed

Please sign in to comment.