Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing return type to generic_syntax_infer_variance.py #1871

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 121 additions & 114 deletions conformance/results/mypy/generics_syntax_infer_variance.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.13.0"
test_duration = 1.5
test_duration = 2.4
36 changes: 18 additions & 18 deletions conformance/results/pyre/generics_syntax_infer_variance.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ notes = """
Type parameter syntax not yet support.
"""
output = """
generics_syntax_infer_variance.py:132:25 Parsing failure [404]: invalid syntax
generics_syntax_infer_variance.py:134:25 Parsing failure [404]: invalid syntax
"""
conformance_automated = "Fail"
errors_diff = """
Line 15: Expected 1 errors
Line 17: Expected 1 errors
Line 29: Expected 1 errors
Line 37: Expected 1 errors
Line 46: Expected 1 errors
Line 75: Expected 1 errors
Line 86: Expected 1 errors
Line 102: Expected 1 errors
Line 103: Expected 1 errors
Line 117: Expected 1 errors
Line 118: Expected 1 errors
Line 125: Expected 1 errors
Line 126: Expected 1 errors
Line 18: Expected 1 errors
Line 22: Expected 1 errors
Line 32: Expected 1 errors
Line 40: Expected 1 errors
Line 48: Expected 1 errors
Line 77: Expected 1 errors
Line 88: Expected 1 errors
Line 104: Expected 1 errors
Line 105: Expected 1 errors
Line 119: Expected 1 errors
Line 120: Expected 1 errors
Line 127: Expected 1 errors
Line 128: Expected 1 errors
Line 136: Expected 1 errors
Line 144: Expected 1 errors
Line 155: Expected 1 errors
Line 132: Unexpected errors ['generics_syntax_infer_variance.py:132:25 Parsing failure [404]: invalid syntax']
Line 129: Expected 1 errors
Line 130: Expected 1 errors
Line 138: Expected 1 errors
Line 146: Expected 1 errors
Line 157: Expected 1 errors
Line 134: Unexpected errors ['generics_syntax_infer_variance.py:134:25 Parsing failure [404]: invalid syntax']
"""
2 changes: 1 addition & 1 deletion conformance/results/pyre/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyre 0.9.22"
test_duration = 4.4
test_duration = 6.1
42 changes: 23 additions & 19 deletions conformance/results/pyright/generics_syntax_infer_variance.toml
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
conformant = "Pass"
output = """
generics_syntax_infer_variance.py:15:51 - error: TypeVar cannot be both covariant and contravariant (reportGeneralTypeIssues)
generics_syntax_infer_variance.py:17:55 - error: TypeVar cannot be both covariant and contravariant (reportGeneralTypeIssues)
generics_syntax_infer_variance.py:29:35 - error: Type "ShouldBeCovariant1[float]" is not assignable to declared type "ShouldBeCovariant1[int]"
generics_syntax_infer_variance.py:17:42 - error: TypeVar cannot be both covariant and contravariant (reportGeneralTypeIssues)
generics_syntax_infer_variance.py:21:46 - error: TypeVar cannot be both covariant and contravariant (reportGeneralTypeIssues)
generics_syntax_infer_variance.py:32:35 - error: Type "ShouldBeCovariant1[float]" is not assignable to declared type "ShouldBeCovariant1[int]"
  "ShouldBeCovariant1[float]" is not assignable to "ShouldBeCovariant1[int]"
    Type parameter "T@ShouldBeCovariant1" is covariant, but "float" is not a subtype of "int"
      "float" is not assignable to "int" (reportAssignmentType)
generics_syntax_infer_variance.py:37:35 - error: Type "ShouldBeCovariant2[float]" is not assignable to declared type "ShouldBeCovariant2[int]"
generics_syntax_infer_variance.py:40:35 - error: Type "ShouldBeCovariant2[float]" is not assignable to declared type "ShouldBeCovariant2[int]"
  "ShouldBeCovariant2[float]" is not assignable to "ShouldBeCovariant2[int]"
    Type parameter "T@ShouldBeCovariant2" is covariant, but "float" is not a subtype of "int"
      "float" is not assignable to "int" (reportAssignmentType)
generics_syntax_infer_variance.py:46:35 - error: Type "ShouldBeCovariant3[float]" is not assignable to declared type "ShouldBeCovariant3[int]"
generics_syntax_infer_variance.py:48:35 - error: Type "ShouldBeCovariant3[float]" is not assignable to declared type "ShouldBeCovariant3[int]"
  "ShouldBeCovariant3[float]" is not assignable to "ShouldBeCovariant3[int]"
    Type parameter "T@ShouldBeCovariant3" is covariant, but "float" is not a subtype of "int"
      "float" is not assignable to "int" (reportAssignmentType)
generics_syntax_infer_variance.py:75:34 - error: Type "ShouldBeCovariant5[float]" is not assignable to declared type "ShouldBeCovariant5[int]"
generics_syntax_infer_variance.py:77:34 - error: Type "ShouldBeCovariant5[float]" is not assignable to declared type "ShouldBeCovariant5[int]"
  "ShouldBeCovariant5[float]" is not assignable to "ShouldBeCovariant5[int]"
    Type parameter "T@ShouldBeCovariant5" is covariant, but "float" is not a subtype of "int"
      "float" is not assignable to "int" (reportAssignmentType)
generics_syntax_infer_variance.py:86:34 - error: Type "ShouldBeCovariant6[float]" is not assignable to declared type "ShouldBeCovariant6[int]"
generics_syntax_infer_variance.py:88:34 - error: Type "ShouldBeCovariant6[float]" is not assignable to declared type "ShouldBeCovariant6[int]"
  "ShouldBeCovariant6[float]" is not assignable to "ShouldBeCovariant6[int]"
    Type parameter "T@ShouldBeCovariant6" is covariant, but "float" is not a subtype of "int"
      "float" is not assignable to "int" (reportAssignmentType)
generics_syntax_infer_variance.py:102:38 - error: Type "ShouldBeInvariant1[int]" is not assignable to declared type "ShouldBeInvariant1[float]"
generics_syntax_infer_variance.py:104:38 - error: Type "ShouldBeInvariant1[int]" is not assignable to declared type "ShouldBeInvariant1[float]"
  "ShouldBeInvariant1[int]" is not assignable to "ShouldBeInvariant1[float]"
    Type parameter "T@ShouldBeInvariant1" is invariant, but "int" is not the same as "float" (reportAssignmentType)
generics_syntax_infer_variance.py:103:36 - error: Type "ShouldBeInvariant1[float]" is not assignable to declared type "ShouldBeInvariant1[int]"
generics_syntax_infer_variance.py:105:36 - error: Type "ShouldBeInvariant1[float]" is not assignable to declared type "ShouldBeInvariant1[int]"
  "ShouldBeInvariant1[float]" is not assignable to "ShouldBeInvariant1[int]"
    Type parameter "T@ShouldBeInvariant1" is invariant, but "float" is not the same as "int" (reportAssignmentType)
generics_syntax_infer_variance.py:117:38 - error: Type "ShouldBeInvariant2[int]" is not assignable to declared type "ShouldBeInvariant2[float]"
generics_syntax_infer_variance.py:119:38 - error: Type "ShouldBeInvariant2[int]" is not assignable to declared type "ShouldBeInvariant2[float]"
  "ShouldBeInvariant2[int]" is not assignable to "ShouldBeInvariant2[float]"
    Type parameter "T@ShouldBeInvariant2" is invariant, but "int" is not the same as "float" (reportAssignmentType)
generics_syntax_infer_variance.py:118:36 - error: Type "ShouldBeInvariant2[float]" is not assignable to declared type "ShouldBeInvariant2[int]"
generics_syntax_infer_variance.py:120:36 - error: Type "ShouldBeInvariant2[float]" is not assignable to declared type "ShouldBeInvariant2[int]"
  "ShouldBeInvariant2[float]" is not assignable to "ShouldBeInvariant2[int]"
    Type parameter "T@ShouldBeInvariant2" is invariant, but "float" is not the same as "int" (reportAssignmentType)
generics_syntax_infer_variance.py:125:43 - error: Type "ShouldBeInvariant3[int, str]" is not assignable to declared type "ShouldBeInvariant3[float, str]"
generics_syntax_infer_variance.py:127:43 - error: Type "ShouldBeInvariant3[int, str]" is not assignable to declared type "ShouldBeInvariant3[float, str]"
  "ShouldBeInvariant3[int, str]" is not assignable to "ShouldBeInvariant3[float, str]"
    Type parameter "K@ShouldBeInvariant3" is invariant, but "int" is not the same as "float" (reportAssignmentType)
generics_syntax_infer_variance.py:126:41 - error: Type "ShouldBeInvariant3[float, str]" is not assignable to declared type "ShouldBeInvariant3[int, str]"
generics_syntax_infer_variance.py:128:41 - error: Type "ShouldBeInvariant3[float, str]" is not assignable to declared type "ShouldBeInvariant3[int, str]"
  "ShouldBeInvariant3[float, str]" is not assignable to "ShouldBeInvariant3[int, str]"
    Type parameter "K@ShouldBeInvariant3" is invariant, but "float" is not the same as "int" (reportAssignmentType)
generics_syntax_infer_variance.py:127:43 - error: Type "ShouldBeInvariant3[str, int]" is not assignable to declared type "ShouldBeInvariant3[str, float]"
generics_syntax_infer_variance.py:129:43 - error: Type "ShouldBeInvariant3[str, int]" is not assignable to declared type "ShouldBeInvariant3[str, float]"
  "ShouldBeInvariant3[str, int]" is not assignable to "ShouldBeInvariant3[str, float]"
    Type parameter "V@ShouldBeInvariant3" is invariant, but "int" is not the same as "float" (reportAssignmentType)
generics_syntax_infer_variance.py:128:41 - error: Type "ShouldBeInvariant3[str, float]" is not assignable to declared type "ShouldBeInvariant3[str, int]"
generics_syntax_infer_variance.py:130:41 - error: Type "ShouldBeInvariant3[str, float]" is not assignable to declared type "ShouldBeInvariant3[str, int]"
  "ShouldBeInvariant3[str, float]" is not assignable to "ShouldBeInvariant3[str, int]"
    Type parameter "V@ShouldBeInvariant3" is invariant, but "float" is not the same as "int" (reportAssignmentType)
generics_syntax_infer_variance.py:136:38 - error: Type "ShouldBeInvariant4[int]" is not assignable to declared type "ShouldBeInvariant4[float]"
generics_syntax_infer_variance.py:138:38 - error: Type "ShouldBeInvariant4[int]" is not assignable to declared type "ShouldBeInvariant4[float]"
  "ShouldBeInvariant4[int]" is not assignable to "ShouldBeInvariant4[float]"
    Type parameter "T@ShouldBeInvariant4" is invariant, but "int" is not the same as "float" (reportAssignmentType)
generics_syntax_infer_variance.py:144:38 - error: Type "ShouldBeInvariant5[int]" is not assignable to declared type "ShouldBeInvariant5[float]"
generics_syntax_infer_variance.py:146:38 - error: Type "ShouldBeInvariant5[int]" is not assignable to declared type "ShouldBeInvariant5[float]"
  "ShouldBeInvariant5[int]" is not assignable to "ShouldBeInvariant5[float]"
    Type parameter "T@ShouldBeInvariant5" is invariant, but "int" is not the same as "float" (reportAssignmentType)
generics_syntax_infer_variance.py:155:45 - error: Type "ShouldBeContravariant1[int]" is not assignable to declared type "ShouldBeContravariant1[float]"
generics_syntax_infer_variance.py:157:45 - error: Type "ShouldBeContravariant1[int]" is not assignable to declared type "ShouldBeContravariant1[float]"
  "ShouldBeContravariant1[int]" is not assignable to "ShouldBeContravariant1[float]"
    Type parameter "T@ShouldBeContravariant1" is contravariant, but "int" is not a supertype of "float"
      "float" is not assignable to "int" (reportAssignmentType)
"""
conformance_automated = "Pass"
conformance_automated = "Fail"
errors_diff = """
Line 18: Expected 1 errors
Line 22: Expected 1 errors
Line 17: Unexpected errors ['generics_syntax_infer_variance.py:17:42 - error: TypeVar cannot be both covariant and contravariant (reportGeneralTypeIssues)']
migeed-z marked this conversation as resolved.
Show resolved Hide resolved
Line 21: Unexpected errors ['generics_syntax_infer_variance.py:21:46 - error: TypeVar cannot be both covariant and contravariant (reportGeneralTypeIssues)']
"""
2 changes: 1 addition & 1 deletion conformance/results/pyright/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyright 1.1.386"
test_duration = 1.2
test_duration = 1.8
34 changes: 17 additions & 17 deletions conformance/results/pytype/generics_syntax_infer_variance.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ notes = """
Type parameter syntax not yet support.
"""
output = """
SyntaxError: Type parameter lists are only supported in Python 3.12 and greater (<unknown>, line 132)
SyntaxError: Type parameter lists are only supported in Python 3.12 and greater (<unknown>, line 134)
"""
conformance_automated = "Fail"
errors_diff = """
Line 15: Expected 1 errors
Line 17: Expected 1 errors
Line 29: Expected 1 errors
Line 37: Expected 1 errors
Line 46: Expected 1 errors
Line 75: Expected 1 errors
Line 86: Expected 1 errors
Line 102: Expected 1 errors
Line 103: Expected 1 errors
Line 117: Expected 1 errors
Line 118: Expected 1 errors
Line 125: Expected 1 errors
Line 126: Expected 1 errors
Line 18: Expected 1 errors
Line 22: Expected 1 errors
Line 32: Expected 1 errors
Line 40: Expected 1 errors
Line 48: Expected 1 errors
Line 77: Expected 1 errors
Line 88: Expected 1 errors
Line 104: Expected 1 errors
Line 105: Expected 1 errors
Line 119: Expected 1 errors
Line 120: Expected 1 errors
Line 127: Expected 1 errors
Line 128: Expected 1 errors
Line 136: Expected 1 errors
Line 144: Expected 1 errors
Line 155: Expected 1 errors
Line 129: Expected 1 errors
Line 130: Expected 1 errors
Line 138: Expected 1 errors
Line 146: Expected 1 errors
Line 157: Expected 1 errors
"""
7 changes: 3 additions & 4 deletions conformance/results/pytype/specialtypes_never.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ specialtypes_never.py:11:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in <mod
T_co = TypeVar("T_co", covariant=True)
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m

specialtypes_never.py:21:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func1: bad return type [bad-return-type]
specialtypes_never.py:21:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func1: bad return type [bad-return-type]

sys.exit(1) \u001b[1m\u001b[31m~~~~~~~~~~~\u001b[39m\u001b[0m
sys.exit(1)
\u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m
\u001b[1m\u001b[31m~~~~~~~~~~~~~~~\u001b[39m\u001b[0m

specialtypes_never.py:68:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in func6: Type annotation for v1 does not match type of assignment [annotation-type-mismatch]

Expand Down Expand Up @@ -40,7 +39,7 @@ errors_diff = """
Line 19: Expected 1 errors
Line 105: Expected 1 errors
Line 11: Unexpected errors ['specialtypes_never.py:11:8: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]']
Line 21: Unexpected errors ['specialtypes_never.py:21:8: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func1: bad return type [bad-return-type]']
Line 21: Unexpected errors ['specialtypes_never.py:21:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func1: bad return type [bad-return-type]']
Line 68: Unexpected errors ['specialtypes_never.py:68:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func6: Type annotation for v1 does not match type of assignment [annotation-type-mismatch]']
Line 69: Unexpected errors ['specialtypes_never.py:69:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func6: Type annotation for v2 does not match type of assignment [annotation-type-mismatch]']
Line 70: Unexpected errors ['specialtypes_never.py:70:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in func6: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]']
Expand Down
2 changes: 1 addition & 1 deletion conformance/results/pytype/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pytype 2024.10.11"
test_duration = 33.1
test_duration = 47.7
8 changes: 4 additions & 4 deletions conformance/results/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ <h3>Python Type System Conformance Test Results</h3>
<div class="table_container"><table><tbody>
<tr><th class="col1">&nbsp;</th>
<th class='tc-header'><div class='tc-name'>mypy 1.13.0</div>
<div class='tc-time'>1.5sec</div>
<div class='tc-time'>2.4sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyright 1.1.386</div>
<div class='tc-time'>1.2sec</div>
<div class='tc-time'>1.8sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyre 0.9.22</div>
<div class='tc-time'>4.4sec</div>
<div class='tc-time'>6.1sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
<div class='tc-time'>33.1sec</div>
<div class='tc-time'>47.7sec</div>
</th>
</tr>
<tr><th class="column" colspan="5">
Expand Down
22 changes: 12 additions & 10 deletions conformance/tests/generics_syntax_infer_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@
Tests the handling of "infer_variance" parameter for TypeVar.
"""

from dataclasses import dataclass
migeed-z marked this conversation as resolved.
Show resolved Hide resolved

# Specification: https://peps.python.org/pep-0695/#auto-variance-for-typevar

from typing import Final, Generic, Iterator, Sequence, TypeVar
from dataclasses import dataclass


T = TypeVar("T", infer_variance=True)
K = TypeVar("K", infer_variance=True)
V = TypeVar("V", infer_variance=True)

S1 = TypeVar("S1", covariant=True, infer_variance=True) # E: cannot use covariant with infer_variance
S1 = TypeVar(
"S1", covariant=True, infer_variance=True
) # E: cannot use covariant with infer_variance
migeed-z marked this conversation as resolved.
Show resolved Hide resolved

S2 = TypeVar("S2", contravariant=True, infer_variance=True) # E: cannot use contravariant with infer_variance
S2 = TypeVar(
"S2", contravariant=True, infer_variance=True
) # E: cannot use contravariant with infer_variance


class ShouldBeCovariant1(Generic[T]):
def __getitem__(self, index: int) -> T:
...
def __getitem__(self, index: int) -> T: ...
migeed-z marked this conversation as resolved.
Show resolved Hide resolved

def __iter__(self) -> Iterator[T]:
...
def __iter__(self) -> Iterator[T]: ...


vco1_1: ShouldBeCovariant1[float] = ShouldBeCovariant1[int]() # OK
Expand All @@ -38,8 +41,7 @@ class ShouldBeCovariant2(Sequence[T]):


class ShouldBeCovariant3(Generic[T]):
def method1(self) -> "ShouldBeCovariant2[T]":
...
def method1(self) -> "ShouldBeCovariant2[T]": ...


vco3_1: ShouldBeCovariant3[float] = ShouldBeCovariant3[int]() # OK
Expand Down Expand Up @@ -91,7 +93,7 @@ def __init__(self, value: T) -> None:
self._value = value

@property
def value(self):
def value(self) -> T:
return self._value

@value.setter
Expand Down