Fix mypy and pyright tests in CI (#1202)

Some error messages changed in mypy 1.7.0 and pyright 1.1.335.

Also, test_mypy sometimes fails with xdist (-n auto). A failure I can
reliably reproduce locally is due to changes in type variables numbering.
There may be other issues.
This commit is contained in:
Eugene Toder 2023-11-11 05:45:04 -05:00 committed by GitHub
parent 1955f72507
commit ea1037cc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 29 deletions

View File

@ -209,16 +209,17 @@
reveal_type(A) # N: Revealed type is "def (b: Any) -> main.A" reveal_type(A) # N: Revealed type is "def (b: Any) -> main.A"
- case: testAttrsCmpTrue - case: testAttrsCmpTrue
regex: true
main: | main: |
from attr import attrib, attrs from attr import attrib, attrs
@attrs(auto_attribs=True) @attrs(auto_attribs=True)
class A: class A:
a: int a: int
reveal_type(A) # N: Revealed type is "def (a: builtins.int) -> main.A" reveal_type(A) # N: Revealed type is "def \(a: builtins.int\) -> main.A"
reveal_type(A.__lt__) # N: Revealed type is "def [_AT] (self: _AT`3, other: _AT`3) -> builtins.bool" reveal_type(A.__lt__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
reveal_type(A.__le__) # N: Revealed type is "def [_AT] (self: _AT`4, other: _AT`4) -> builtins.bool" reveal_type(A.__le__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
reveal_type(A.__gt__) # N: Revealed type is "def [_AT] (self: _AT`5, other: _AT`5) -> builtins.bool" reveal_type(A.__gt__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
reveal_type(A.__ge__) # N: Revealed type is "def [_AT] (self: _AT`6, other: _AT`6) -> builtins.bool" reveal_type(A.__ge__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
A(1) < A(2) A(1) < A(2)
A(1) <= A(2) A(1) <= A(2)
@ -227,17 +228,17 @@
A(1) == A(2) A(1) == A(2)
A(1) != A(2) A(1) != A(2)
A(1) < 1 # E: Unsupported operand types for < ("A" and "int") [operator] A(1) < 1 # E: Unsupported operand types for < \("A" and "int"\) \[operator\]
A(1) <= 1 # E: Unsupported operand types for <= ("A" and "int") [operator] A(1) <= 1 # E: Unsupported operand types for <= \("A" and "int"\) \[operator\]
A(1) > 1 # E: Unsupported operand types for > ("A" and "int") [operator] A(1) > 1 # E: Unsupported operand types for > \("A" and "int"\) \[operator\]
A(1) >= 1 # E: Unsupported operand types for >= ("A" and "int") [operator] A(1) >= 1 # E: Unsupported operand types for >= \("A" and "int"\) \[operator\]
A(1) == 1 A(1) == 1
A(1) != 1 A(1) != 1
1 < A(1) # E: Unsupported operand types for < ("int" and "A") [operator] 1 < A(1) # E: Unsupported operand types for < \("int" and "A"\) \[operator\]
1 <= A(1) # E: Unsupported operand types for <= ("int" and "A") [operator] 1 <= A(1) # E: Unsupported operand types for <= \("int" and "A"\) \[operator\]
1 > A(1) # E: Unsupported operand types for > ("int" and "A") [operator] 1 > A(1) # E: Unsupported operand types for > \("int" and "A"\) \[operator\]
1 >= A(1) # E: Unsupported operand types for >= ("int" and "A") [operator] 1 >= A(1) # E: Unsupported operand types for >= \("int" and "A"\) \[operator\]
1 == A(1) 1 == A(1)
1 != A(1) 1 != A(1)
@ -874,6 +875,7 @@
o = C(1, 2, "3") o = C(1, 2, "3")
- case: testAttrsCmpWithSubclasses - case: testAttrsCmpWithSubclasses
regex: true
main: | main: |
import attr import attr
@attr.s @attr.s
@ -885,29 +887,29 @@
@attr.s @attr.s
class D(A): pass class D(A): pass
reveal_type(A.__lt__) # N: Revealed type is "def [_AT] (self: _AT`5, other: _AT`5) -> builtins.bool" reveal_type(A.__lt__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
reveal_type(B.__lt__) # N: Revealed type is "def [_AT] (self: _AT`6, other: _AT`6) -> builtins.bool" reveal_type(B.__lt__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
reveal_type(C.__lt__) # N: Revealed type is "def [_AT] (self: _AT`7, other: _AT`7) -> builtins.bool" reveal_type(C.__lt__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
reveal_type(D.__lt__) # N: Revealed type is "def [_AT] (self: _AT`8, other: _AT`8) -> builtins.bool" reveal_type(D.__lt__) # N: Revealed type is "def \[_AT\] \(self: _AT`\d+, other: _AT`\d+\) -> builtins.bool"
A() < A() A() < A()
B() < B() B() < B()
A() < B() # E: Unsupported operand types for < ("A" and "B") [operator] A() < B() # E: Unsupported operand types for < \("A" and "B"\) \[operator\]
C() > A() C() > A()
C() > B() C() > B()
C() > C() C() > C()
C() > D() # E: Unsupported operand types for > ("C" and "D") [operator] C() > D() # E: Unsupported operand types for > \("C" and "D"\) \[operator\]
D() >= A() D() >= A()
D() >= B() # E: Unsupported operand types for >= ("D" and "B") [operator] D() >= B() # E: Unsupported operand types for >= \("D" and "B"\) \[operator\]
D() >= C() # E: Unsupported operand types for >= ("D" and "C") [operator] D() >= C() # E: Unsupported operand types for >= \("D" and "C"\) \[operator\]
D() >= D() D() >= D()
A() <= 1 # E: Unsupported operand types for <= ("A" and "int") [operator] A() <= 1 # E: Unsupported operand types for <= \("A" and "int"\) \[operator\]
B() <= 1 # E: Unsupported operand types for <= ("B" and "int") [operator] B() <= 1 # E: Unsupported operand types for <= \("B" and "int"\) \[operator\]
C() <= 1 # E: Unsupported operand types for <= ("C" and "int") [operator] C() <= 1 # E: Unsupported operand types for <= \("C" and "int"\) \[operator\]
D() <= 1 # E: Unsupported operand types for <= ("D" and "int") [operator] D() <= 1 # E: Unsupported operand types for <= \("D" and "int"\) \[operator\]
- case: testAttrsComplexSuperclass - case: testAttrsComplexSuperclass
main: | main: |
@ -1075,7 +1077,7 @@
return 7 return 7
@attr.s @attr.s
class A: class A:
x: int = attr.ib(factory=list) # E: Incompatible types in assignment \(expression has type "[Ll]ist\[_T\]", variable has type "int"\) \[assignment\] x: int = attr.ib(factory=list) # E: Incompatible types in assignment \(expression has type "[Ll]ist\[.*\]", variable has type "int"\) \[assignment\]
y: str = attr.ib(factory=my_factory) # E: Incompatible types in assignment \(expression has type "int", variable has type "str"\) \[assignment\] y: str = attr.ib(factory=my_factory) # E: Incompatible types in assignment \(expression has type "int", variable has type "str"\) \[assignment\]
- case: testAttrsDefaultAndInit - case: testAttrsDefaultAndInit
@ -1378,7 +1380,7 @@
a: int a: int
b: str b: str
fields(A) # E: Argument 1 to "fields" has incompatible type "[Tt]ype\[A\]"; expected an attrs class \[misc\] # E: Argument 1 to "fields" has incompatible type "[Tt]ype\[A\]"; expected "[Tt]ype\[AttrsInstance\]" \[arg-type\] fields(A) # E: Argument 1 to "fields" has incompatible type "[Tt]ype\[A\]"; expected "[Tt]ype\[AttrsInstance\]" \[arg-type\]
- case: testAsDict - case: testAsDict
main: | main: |

View File

@ -65,7 +65,7 @@ def test_pyright_baseline():
PyrightDiagnostic( PyrightDiagnostic(
severity="error", severity="error",
message='Cannot assign member "a" for type ' message='Cannot assign member "a" for type '
'"Frozen"\n\xa0\xa0"Frozen" is frozen', '"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0Member "__set__" is unknown',
), ),
PyrightDiagnostic( PyrightDiagnostic(
severity="information", severity="information",
@ -74,7 +74,8 @@ def test_pyright_baseline():
PyrightDiagnostic( PyrightDiagnostic(
severity="error", severity="error",
message='Cannot assign member "a" for type ' message='Cannot assign member "a" for type '
'"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen', '"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen\n\xa0\xa0\xa0\xa0'
'Member "__set__" is unknown',
), ),
PyrightDiagnostic( PyrightDiagnostic(
severity="information", severity="information",