Skip to content

Commit

Permalink
update generics_syntax_infer_variance.py
Browse files Browse the repository at this point in the history
  • Loading branch information
migeed-z committed Oct 24, 2024
1 parent c60cd70 commit 3e4c5a9
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 198 deletions.
238 changes: 117 additions & 121 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 = 2.4
test_duration = 2.6
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:134:25 Parsing failure [404]: invalid syntax
generics_syntax_infer_variance.py:132:25 Parsing failure [404]: invalid syntax
"""
conformance_automated = "Fail"
errors_diff = """
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 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 127: Expected 1 errors
Line 128: 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
Line 134: Unexpected errors ['generics_syntax_infer_variance.py:134:25 Parsing failure [404]: invalid syntax']
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']
"""
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 = 6.1
test_duration = 6.5
42 changes: 19 additions & 23 deletions conformance/results/pyright/generics_syntax_infer_variance.toml
Original file line number Diff line number Diff line change
@@ -1,66 +1,62 @@
conformant = "Pass"
output = """
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]"
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]"
  "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:40:35 - error: Type "ShouldBeCovariant2[float]" is not assignable to declared type "ShouldBeCovariant2[int]"
generics_syntax_infer_variance.py:37: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:48:35 - error: Type "ShouldBeCovariant3[float]" is not assignable to declared type "ShouldBeCovariant3[int]"
generics_syntax_infer_variance.py:46: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:77:34 - error: Type "ShouldBeCovariant5[float]" is not assignable to declared type "ShouldBeCovariant5[int]"
generics_syntax_infer_variance.py:75: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:88:34 - error: Type "ShouldBeCovariant6[float]" is not assignable to declared type "ShouldBeCovariant6[int]"
generics_syntax_infer_variance.py:86: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:104:38 - error: Type "ShouldBeInvariant1[int]" is not assignable to declared type "ShouldBeInvariant1[float]"
generics_syntax_infer_variance.py:102: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:105:36 - error: Type "ShouldBeInvariant1[float]" is not assignable to declared type "ShouldBeInvariant1[int]"
generics_syntax_infer_variance.py:103: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:119:38 - error: Type "ShouldBeInvariant2[int]" is not assignable to declared type "ShouldBeInvariant2[float]"
generics_syntax_infer_variance.py:117: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:120:36 - error: Type "ShouldBeInvariant2[float]" is not assignable to declared type "ShouldBeInvariant2[int]"
generics_syntax_infer_variance.py:118: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:127:43 - error: Type "ShouldBeInvariant3[int, str]" is not assignable to declared type "ShouldBeInvariant3[float, str]"
generics_syntax_infer_variance.py:125: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:128:41 - error: Type "ShouldBeInvariant3[float, str]" is not assignable to declared type "ShouldBeInvariant3[int, str]"
generics_syntax_infer_variance.py:126: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:129:43 - error: Type "ShouldBeInvariant3[str, int]" is not assignable to declared type "ShouldBeInvariant3[str, float]"
generics_syntax_infer_variance.py:127: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:130:41 - error: Type "ShouldBeInvariant3[str, float]" is not assignable to declared type "ShouldBeInvariant3[str, int]"
generics_syntax_infer_variance.py:128: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:138:38 - error: Type "ShouldBeInvariant4[int]" is not assignable to declared type "ShouldBeInvariant4[float]"
generics_syntax_infer_variance.py:136: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:146:38 - error: Type "ShouldBeInvariant5[int]" is not assignable to declared type "ShouldBeInvariant5[float]"
generics_syntax_infer_variance.py:144: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:157:45 - error: Type "ShouldBeContravariant1[int]" is not assignable to declared type "ShouldBeContravariant1[float]"
generics_syntax_infer_variance.py:155: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 = "Fail"
conformance_automated = "Pass"
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)']
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.8
test_duration = 1.9
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 134)
SyntaxError: Type parameter lists are only supported in Python 3.12 and greater (<unknown>, line 132)
"""
conformance_automated = "Fail"
errors_diff = """
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 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 127: Expected 1 errors
Line 128: 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
Line 136: Expected 1 errors
Line 144: Expected 1 errors
Line 155: Expected 1 errors
"""
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 = 47.7
test_duration = 50.2
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'>2.4sec</div>
<div class='tc-time'>2.6sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyright 1.1.386</div>
<div class='tc-time'>1.8sec</div>
<div class='tc-time'>1.9sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pyre 0.9.22</div>
<div class='tc-time'>6.1sec</div>
<div class='tc-time'>6.5sec</div>
</th>
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
<div class='tc-time'>47.7sec</div>
<div class='tc-time'>50.2sec</div>
</th>
</tr>
<tr><th class="column" colspan="5">
Expand Down
20 changes: 9 additions & 11 deletions conformance/tests/generics_syntax_infer_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@
Tests the handling of "infer_variance" parameter for TypeVar.
"""

from dataclasses import dataclass

# 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

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:
...

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


vco1_1: ShouldBeCovariant1[float] = ShouldBeCovariant1[int]() # OK
Expand All @@ -41,7 +38,8 @@ 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

0 comments on commit 3e4c5a9

Please sign in to comment.