Skip to content

Commit 2bb782c

Browse files
committed
Update check-plugin-attrs.test file
1 parent eba288b commit 2bb782c

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

test-data/unit/check-plugin-attrs.test

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ class A:
3131
reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A"
3232
A(1, [2])
3333
A(1, [2], '3', 4)
34-
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" \
34+
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" \
3535
# E: Argument 3 to "A" has incompatible type "int"; expected "str"
3636
A(1, [2], '3', 4, 5) # E: Too many arguments for "A"
37+
3738
[builtins fixtures/list.pyi]
3839

3940
[case testAttrsTypeComments]
@@ -50,9 +51,10 @@ class A:
5051
reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A"
5152
A(1, [2])
5253
A(1, [2], '3', 4)
53-
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" \
54+
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" \
5455
# E: Argument 3 to "A" has incompatible type "int"; expected "str"
5556
A(1, [2], '3', 4, 5) # E: Too many arguments for "A"
57+
5658
[builtins fixtures/list.pyi]
5759

5860
[case testAttrsAutoAttribs]
@@ -69,9 +71,10 @@ class A:
6971
reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.list[builtins.int], c: builtins.str =, d: builtins.int =) -> __main__.A"
7072
A(1, [2])
7173
A(1, [2], '3', 4)
72-
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]" \
74+
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]" \
7375
# E: Argument 3 to "A" has incompatible type "int"; expected "str"
7476
A(1, [2], '3', 4, 5) # E: Too many arguments for "A"
77+
7578
[builtins fixtures/list.pyi]
7679

7780
[case testAttrsUntypedNoUntypedDefs]
@@ -123,7 +126,7 @@ class A:
123126
reveal_type(A) # N: Revealed type is "def (a: Any, b: builtins.list[builtins.int], c: Any =, d: Any =) -> __main__.A"
124127
A(1, [2])
125128
A(1, [2], '3', 4)
126-
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "List[int]"
129+
A(1, 2, 3, 4) # E: Argument 2 to "A" has incompatible type "int"; expected "list[int]"
127130
A(1, [2], '3', 4, 5) # E: Too many arguments for "A"
128131
[builtins fixtures/list.pyi]
129132

@@ -466,7 +469,7 @@ class A(Generic[T]):
466469
def bar(self) -> T:
467470
return self.x[0]
468471
def problem(self) -> T:
469-
return self.x # E: Incompatible return value type (got "List[T]", expected "T")
472+
return self.x # E: Incompatible return value type (got "list[T]", expected "T")
470473
reveal_type(A) # N: Revealed type is "def [T] (x: builtins.list[T`1], y: T`1) -> __main__.A[T`1]"
471474
a = A([1], 2)
472475
reveal_type(a) # N: Revealed type is "__main__.A[builtins.int]"
@@ -498,7 +501,7 @@ class A(Generic[T]):
498501
def bar(self) -> T:
499502
return self.x[0]
500503
def problem(self) -> T:
501-
return self.x # E: Incompatible return value type (got "List[T]", expected "T")
504+
return self.x # E: Incompatible return value type (got "list[T]", expected "T")
502505
reveal_type(A) # N: Revealed type is "def [T] (x: typing.Iterable[T`1], y: T`1) -> __main__.A[T`1]"
503506
a1 = A([1], 2)
504507
reveal_type(a1) # N: Revealed type is "__main__.A[builtins.int]"
@@ -671,7 +674,7 @@ class A(Generic[T]):
671674
x: Optional[T]
672675
@classmethod
673676
def clsmeth(cls) -> None:
674-
reveal_type(cls) # N: Revealed type is "Type[__main__.A[T`1]]"
677+
reveal_type(cls) # N: Revealed type is "type[__main__.A[T`1]]"
675678

676679
[builtins fixtures/classmethod.pyi]
677680

@@ -726,7 +729,7 @@ class A:
726729
b: str = attr.ib()
727730
@classmethod
728731
def new(cls) -> A:
729-
reveal_type(cls) # N: Revealed type is "Type[__main__.A]"
732+
reveal_type(cls) # N: Revealed type is "type[__main__.A]"
730733
return cls(6, 'hello')
731734
@classmethod
732735
def bad(cls) -> A:
@@ -761,7 +764,7 @@ class A:
761764

762765
@classmethod
763766
def foo(cls, x: Union[int, str]) -> Union[int, str]:
764-
reveal_type(cls) # N: Revealed type is "Type[__main__.A]"
767+
reveal_type(cls) # N: Revealed type is "type[__main__.A]"
765768
reveal_type(cls.other()) # N: Revealed type is "builtins.str"
766769
return x
767770

@@ -1210,7 +1213,7 @@ def my_factory() -> int:
12101213
return 7
12111214
@attr.s
12121215
class A:
1213-
x: int = attr.ib(factory=list) # E: Incompatible types in assignment (expression has type "List[Never]", variable has type "int")
1216+
x: int = attr.ib(factory=list) # E: Incompatible types in assignment (expression has type "list[Never]", variable has type "int")
12141217
y: str = attr.ib(factory=my_factory) # E: Incompatible types in assignment (expression has type "int", variable has type "str")
12151218
[builtins fixtures/list.pyi]
12161219

@@ -1521,7 +1524,7 @@ class A:
15211524
b: int = attr.ib()
15221525
c: str = attr.ib()
15231526

1524-
reveal_type(A.__attrs_attrs__) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
1527+
reveal_type(A.__attrs_attrs__) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
15251528
reveal_type(A.__attrs_attrs__[0]) # N: Revealed type is "attr.Attribute[builtins.int]"
15261529
reveal_type(A.__attrs_attrs__.b) # N: Revealed type is "attr.Attribute[builtins.int]"
15271530
A.__attrs_attrs__.x # E: "____main___A_AttrsAttributes__" has no attribute "x"
@@ -1536,7 +1539,7 @@ class A:
15361539
b = attr.ib()
15371540
c = attr.ib()
15381541

1539-
reveal_type(A.__attrs_attrs__) # N: Revealed type is "Tuple[attr.Attribute[Any], attr.Attribute[Any], fallback=__main__.A.____main___A_AttrsAttributes__]"
1542+
reveal_type(A.__attrs_attrs__) # N: Revealed type is "tuple[attr.Attribute[Any], attr.Attribute[Any], fallback=__main__.A.____main___A_AttrsAttributes__]"
15401543
reveal_type(A.__attrs_attrs__[0]) # N: Revealed type is "attr.Attribute[Any]"
15411544
reveal_type(A.__attrs_attrs__.b) # N: Revealed type is "attr.Attribute[Any]"
15421545
A.__attrs_attrs__.x # E: "____main___A_AttrsAttributes__" has no attribute "x"
@@ -1551,7 +1554,7 @@ class A:
15511554
b: int
15521555
c: str
15531556

1554-
reveal_type(A.__attrs_attrs__) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
1557+
reveal_type(A.__attrs_attrs__) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
15551558
reveal_type(A.__attrs_attrs__[0]) # N: Revealed type is "attr.Attribute[builtins.int]"
15561559
reveal_type(A.__attrs_attrs__.b) # N: Revealed type is "attr.Attribute[builtins.int]"
15571560
A.__attrs_attrs__.x # E: "____main___A_AttrsAttributes__" has no attribute "x"
@@ -1579,9 +1582,10 @@ def takes_attrs_instance(inst: AttrsInstance) -> None:
15791582
takes_attrs_cls(A)
15801583
takes_attrs_instance(A(1, ""))
15811584

1582-
takes_attrs_cls(A(1, "")) # E: Argument 1 to "takes_attrs_cls" has incompatible type "A"; expected "Type[AttrsInstance]"
1583-
takes_attrs_instance(A) # E: Argument 1 to "takes_attrs_instance" has incompatible type "Type[A]"; expected "AttrsInstance" \
1585+
takes_attrs_cls(A(1, "")) # E: Argument 1 to "takes_attrs_cls" has incompatible type "A"; expected "type[AttrsInstance]"
1586+
takes_attrs_instance(A) # E: Argument 1 to "takes_attrs_instance" has incompatible type "type[A]"; expected "AttrsInstance" \
15841587
# N: ClassVar protocol member AttrsInstance.__attrs_attrs__ can never be matched by a class object
1588+
15851589
[builtins fixtures/plugin_attrs.pyi]
15861590

15871591
[case testAttrsFields]
@@ -1593,7 +1597,7 @@ class A:
15931597
b: int
15941598
c: str
15951599

1596-
reveal_type(f(A)) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
1600+
reveal_type(f(A)) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
15971601
reveal_type(f(A)[0]) # N: Revealed type is "attr.Attribute[builtins.int]"
15981602
reveal_type(f(A).b) # N: Revealed type is "attr.Attribute[builtins.int]"
15991603
f(A).x # E: "____main___A_AttrsAttributes__" has no attribute "x"
@@ -1617,7 +1621,7 @@ class A:
16171621
TA = TypeVar('TA', bound=A)
16181622

16191623
def f(t: TA) -> None:
1620-
reveal_type(fields(t)) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
1624+
reveal_type(fields(t)) # N: Revealed type is "tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
16211625
reveal_type(fields(t)[0]) # N: Revealed type is "attr.Attribute[builtins.int]"
16221626
reveal_type(fields(t).b) # N: Revealed type is "attr.Attribute[builtins.int]"
16231627
fields(t).x # E: "____main___A_AttrsAttributes__" has no attribute "x"
@@ -1636,8 +1640,8 @@ class A:
16361640
if has(A):
16371641
fields(A)
16381642
else:
1639-
fields(A) # E: Argument 1 to "fields" has incompatible type "Type[A]"; expected "Type[AttrsInstance]"
1640-
fields(None) # E: Argument 1 to "fields" has incompatible type "None"; expected "Type[AttrsInstance]"
1643+
fields(A) # E: Argument 1 to "fields" has incompatible type "type[A]"; expected "type[AttrsInstance]"
1644+
fields(None) # E: Argument 1 to "fields" has incompatible type "None"; expected "type[AttrsInstance]"
16411645
fields(cast(Any, 42))
16421646
fields(cast(Type[Any], 43))
16431647

@@ -1655,8 +1659,8 @@ class A:
16551659
b, c = bc
16561660
self.__attrs_init__(b, c)
16571661

1658-
reveal_type(A) # N: Revealed type is "def (bc: Tuple[builtins.int, builtins.str]) -> __main__.A"
1659-
reveal_type(A.__init__) # N: Revealed type is "def (self: __main__.A, bc: Tuple[builtins.int, builtins.str])"
1662+
reveal_type(A) # N: Revealed type is "def (bc: tuple[builtins.int, builtins.str]) -> __main__.A"
1663+
reveal_type(A.__init__) # N: Revealed type is "def (self: __main__.A, bc: tuple[builtins.int, builtins.str])"
16601664
reveal_type(A.__attrs_init__) # N: Revealed type is "def (self: __main__.A, b: builtins.int, c: builtins.str)"
16611665

16621666
[builtins fixtures/plugin_attrs.pyi]
@@ -1733,22 +1737,22 @@ class Some:
17331737
y: str
17341738
z: bool
17351739

1736-
reveal_type(Some.__slots__) # N: Revealed type is "Tuple[builtins.str, builtins.str, builtins.str]"
1740+
reveal_type(Some.__slots__) # N: Revealed type is "tuple[builtins.str, builtins.str, builtins.str]"
17371741

17381742
@dataclass(slots=True)
17391743
class Other:
17401744
x: int
17411745
y: str
17421746

1743-
reveal_type(Other.__slots__) # N: Revealed type is "Tuple[builtins.str, builtins.str]"
1747+
reveal_type(Other.__slots__) # N: Revealed type is "tuple[builtins.str, builtins.str]"
17441748

17451749

17461750
@dataclass
17471751
class NoSlots:
17481752
x: int
17491753
y: str
17501754

1751-
NoSlots.__slots__ # E: "Type[NoSlots]" has no attribute "__slots__"
1755+
NoSlots.__slots__ # E: "type[NoSlots]" has no attribute "__slots__"
17521756
[builtins fixtures/plugin_attrs.pyi]
17531757

17541758
[case testAttrsWithMatchArgs]
@@ -1763,8 +1767,8 @@ class ToMatch:
17631767
z: int = attr.field(kw_only=True)
17641768
i: int = attr.field(init=False)
17651769

1766-
reveal_type(ToMatch(x=1, y=2, z=3).__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]"
1767-
reveal_type(ToMatch(1, 2, z=3).__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]"
1770+
reveal_type(ToMatch(x=1, y=2, z=3).__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]"
1771+
reveal_type(ToMatch(1, 2, z=3).__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]"
17681772
[builtins fixtures/plugin_attrs.pyi]
17691773

17701774
[case testAttrsWithMatchArgsDefaultCase]
@@ -1777,15 +1781,15 @@ class ToMatch1:
17771781
y: int
17781782

17791783
t1: ToMatch1
1780-
reveal_type(t1.__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]"
1784+
reveal_type(t1.__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]"
17811785

17821786
@attr.define
17831787
class ToMatch2:
17841788
x: int
17851789
y: int
17861790

17871791
t2: ToMatch2
1788-
reveal_type(t2.__match_args__) # N: Revealed type is "Tuple[Literal['x']?, Literal['y']?]"
1792+
reveal_type(t2.__match_args__) # N: Revealed type is "tuple[Literal['x']?, Literal['y']?]"
17891793
[builtins fixtures/plugin_attrs.pyi]
17901794

17911795
[case testAttrsWithMatchArgsOverrideExisting]
@@ -1800,15 +1804,15 @@ class ToMatch:
18001804
y: int
18011805

18021806
# It works the same way runtime does:
1803-
reveal_type(ToMatch(x=1, y=2).__match_args__) # N: Revealed type is "Tuple[Literal['a']?, Literal['b']?]"
1807+
reveal_type(ToMatch(x=1, y=2).__match_args__) # N: Revealed type is "tuple[Literal['a']?, Literal['b']?]"
18041808

18051809
@attr.s(auto_attribs=True)
18061810
class WithoutMatch:
18071811
__match_args__: Final = ('a', 'b')
18081812
x: int
18091813
y: int
18101814

1811-
reveal_type(WithoutMatch(x=1, y=2).__match_args__) # N: Revealed type is "Tuple[Literal['a']?, Literal['b']?]"
1815+
reveal_type(WithoutMatch(x=1, y=2).__match_args__) # N: Revealed type is "tuple[Literal['a']?, Literal['b']?]"
18121816
[builtins fixtures/plugin_attrs.pyi]
18131817

18141818
[case testAttrsWithMatchArgsOldVersion]
@@ -2176,7 +2180,7 @@ class B:
21762180
a_or_b: A[int] | B
21772181
a2 = attrs.evolve(a_or_b, x=42, y=True)
21782182
a2 = attrs.evolve(a_or_b, x=42, y=True, z='42') # E: Argument "z" to "evolve" of "Union[A[int], B]" has incompatible type "str"; expected "Never"
2179-
a2 = attrs.evolve(a_or_b, x=42, y=True, w={}) # E: Argument "w" to "evolve" of "Union[A[int], B]" has incompatible type "Dict[Never, Never]"; expected "Never"
2183+
a2 = attrs.evolve(a_or_b, x=42, y=True, w={}) # E: Argument "w" to "evolve" of "Union[A[int], B]" has incompatible type "dict[Never, Never]"; expected "Never"
21802184

21812185
[builtins fixtures/plugin_attrs.pyi]
21822186

0 commit comments

Comments
 (0)