Skip to content

Commit 34e831b

Browse files
committed
Add unit tests to verify fix for python#19003 involving overloaded __init__ methods in attrs classes
1 parent 3b725e9 commit 34e831b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,37 +2498,36 @@ reveal_type(c.run_type) # N: Revealed type is "Union[builtins.int, None]"
24982498
[builtins fixtures/plugin_attrs.pyi]
24992499

25002500
[case testAttrsInitOverload1]
2501+
from typing import Union
25012502
from typing import overload
25022503

25032504
import attrs
25042505

25052506
@attrs.frozen(init=False)
25062507
class C:
2507-
x: "int | str"
2508-
2508+
x: Union[int, str]
25092509
@overload
25102510
def __init__(self, x: int) -> None: ...
25112511

25122512
@overload
25132513
def __init__(self, x: str) -> None: ...
25142514

2515-
def __init__(self, x: "int | str") -> None:
2515+
def __init__(self, x: Union[int, str]) -> None:
25162516
self.__attrs_init__(x)
25172517

2518-
25192518
obj = C(1)
25202519
attrs.evolve(obj, x=2)
2521-
attrs.evolve(obj, x="2")
25222520
[builtins fixtures/plugin_attrs.pyi]
25232521

25242522
[case testAttrsInitOverload2]
2523+
from typing import Union
25252524
import attrs
25262525

25272526
@attrs.frozen(init=False)
25282527
class C:
2529-
x: "int | str"
2528+
x: Union[int, str]
25302529

2531-
def __init__(self, x: "int | str", y: bool) -> None:
2530+
def __init__(self, x: Union[int, str], y: bool) -> None:
25322531
self.__attrs_init__(x)
25332532

25342533
obj = C(1, False)

0 commit comments

Comments
 (0)