You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This reverts commit 391ed85.
The use of a Union item type for `attr.Attribute` would likely be
more useful to callsites of `attr.fields` - otherwise this currently
results in inferring `builtins.object` in many cases where we treat
the fields as a variable-length tuple, rather than a fixed-length
one. Applications of the fixed-length tuple seem limited since you
would need to access it by index.
@Tinche as the original author of the commit.
Copy file name to clipboardexpand all lines: test-data/unit/check-plugin-attrs.test
-53
Original file line number
Diff line number
Diff line change
@@ -1553,59 +1553,6 @@ takes_attrs_cls(A(1, "")) # E: Argument 1 to "takes_attrs_cls" has incompatible
1553
1553
takes_attrs_instance(A) # E: Argument 1 to "takes_attrs_instance" has incompatible type "Type[A]"; expected "AttrsInstance" # N: ClassVar protocol member AttrsInstance.__attrs_attrs__ can never be matched by a class object
1554
1554
[builtins fixtures/plugin_attrs.pyi]
1555
1555
1556
-
[case testAttrsFields]
1557
-
import attr
1558
-
from attrs import fields as f # Common usage.
1559
-
1560
-
@attr.define
1561
-
class A:
1562
-
b: int
1563
-
c: str
1564
-
1565
-
reveal_type(f(A)) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
1566
-
reveal_type(f(A)[0]) # N: Revealed type is "attr.Attribute[builtins.int]"
1567
-
reveal_type(f(A).b) # N: Revealed type is "attr.Attribute[builtins.int]"
1568
-
f(A).x # E: "____main___A_AttrsAttributes__" has no attribute "x"
1569
-
1570
-
[builtins fixtures/plugin_attrs.pyi]
1571
-
1572
-
[case testAttrsGenericFields]
1573
-
from typing import TypeVar
1574
-
1575
-
import attr
1576
-
from attrs import fields
1577
-
1578
-
@attr.define
1579
-
class A:
1580
-
b: int
1581
-
c: str
1582
-
1583
-
TA = TypeVar('TA', bound=A)
1584
-
1585
-
def f(t: TA) -> None:
1586
-
reveal_type(fields(t)) # N: Revealed type is "Tuple[attr.Attribute[builtins.int], attr.Attribute[builtins.str], fallback=__main__.A.____main___A_AttrsAttributes__]"
1587
-
reveal_type(fields(t)[0]) # N: Revealed type is "attr.Attribute[builtins.int]"
1588
-
reveal_type(fields(t).b) # N: Revealed type is "attr.Attribute[builtins.int]"
1589
-
fields(t).x # E: "____main___A_AttrsAttributes__" has no attribute "x"
1590
-
1591
-
1592
-
[builtins fixtures/plugin_attrs.pyi]
1593
-
1594
-
[case testNonattrsFields]
1595
-
from typing import Any, cast, Type
1596
-
from attrs import fields
1597
-
1598
-
class A:
1599
-
b: int
1600
-
c: str
1601
-
1602
-
fields(A) # E: Argument 1 to "fields" has incompatible type "Type[A]"; expected an attrs class
1603
-
fields(None) # E: Argument 1 to "fields" has incompatible type "None"; expected an attrs class
0 commit comments