Skip to content

Commit 591bf88

Browse files
committed
Show that attrs auto_detect does not work
This test demonstrates that addition of dunder methods in attrs classes isn't quite complete. While the existing test demonstrates that it was working for classes defined with `init=False`, the `__attrs_init__` method wasn't generated in the same way when `__init__` was defined with `auto_detect=True` enabled (either explicitly, or by default). This auto-generated `__attrs_init__` has been enabled in Attrs as of version 21.1.0. Related to: python#10328 Ref: python-attrs/attrs#793 Ref: https://www.attrs.org/en/stable/changelog.html
1 parent 1dd8e7f commit 591bf88

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,42 @@ reveal_type(A.__attrs_init__) # N: Revealed type is "def (self: __main__.A, b:
16561656

16571657
[builtins fixtures/plugin_attrs.pyi]
16581658

1659+
[case testAttrsInitMethodGeneratedWhenAutoDetectTrue]
1660+
from typing import Tuple
1661+
import attr
1662+
1663+
@attr.define(auto_detect=True)
1664+
class A:
1665+
b: int
1666+
c: str
1667+
def __init__(self, bc: Tuple[int, str]) -> None:
1668+
b, c = bc
1669+
self.__attrs_init__(b, c)
1670+
1671+
reveal_type(A) # N: Revealed type is "def (bc: Tuple[builtins.int, builtins.str]) -> __main__.A"
1672+
reveal_type(A.__init__) # N: Revealed type is "def (self: __main__.A, bc: Tuple[builtins.int, builtins.str])"
1673+
reveal_type(A.__attrs_init__) # N: Revealed type is "def (self: __main__.A, b: builtins.int, c: builtins.str)"
1674+
1675+
[builtins fixtures/plugin_attrs.pyi]
1676+
1677+
[case testAttrsInitMethodGeneratedWhenAutoDetectTrueDefault]
1678+
from typing import Tuple
1679+
import attr
1680+
1681+
@attr.define
1682+
class A:
1683+
b: int
1684+
c: str
1685+
def __init__(self, bc: Tuple[int, str]) -> None:
1686+
b, c = bc
1687+
self.__attrs_init__(b, c)
1688+
1689+
reveal_type(A) # N: Revealed type is "def (bc: Tuple[builtins.int, builtins.str]) -> __main__.A"
1690+
reveal_type(A.__init__) # N: Revealed type is "def (self: __main__.A, bc: Tuple[builtins.int, builtins.str])"
1691+
reveal_type(A.__attrs_init__) # N: Revealed type is "def (self: __main__.A, b: builtins.int, c: builtins.str)"
1692+
1693+
[builtins fixtures/plugin_attrs.pyi]
1694+
16591695
[case testAttrsClassWithSlots]
16601696
import attr
16611697

0 commit comments

Comments
 (0)