Skip to content

Commit befa170

Browse files
committed
Add more advanced test
1 parent 531f724 commit befa170

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

test-data/unit/check-attr.test

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ A([1], '2') # E: Cannot infer type argument 1 of "A"
470470
[builtins fixtures/list.pyi]
471471

472472
[case testAttrsGenericWithConverter]
473-
from typing import TypeVar, Generic, List, Iterable, Iterator
473+
from typing import TypeVar, Generic, List, Iterable, Iterator, Callable
474474
import attr
475475
T = TypeVar('T')
476476

@@ -501,13 +501,24 @@ reveal_type(a2) # N: Revealed type is "__main__.A[builtins.int]"
501501
reveal_type(a2.x) # N: Revealed type is "builtins.list[builtins.int]"
502502
reveal_type(a2.y) # N: Revealed type is "builtins.int"
503503

504-
# Leaving this as a sanity check
505-
class B(Generic[T]):
506-
def __init__(self, x: Iterable[T], y: T) -> None:
504+
505+
def get_int() -> int:
506+
return 1
507+
508+
class Other(Generic[T]):
509+
def __init__(self, x: T) -> None:
507510
pass
508511

509-
B(['str'], 7)
510-
B([1], '2')
512+
def other_converter(x: Callable[..., T]) -> Other[Callable[..., T]]:
513+
return Other(x)
514+
515+
@attr.s(auto_attribs=True)
516+
class B(Generic[T]):
517+
x: Other[Callable[..., T]] = attr.ib(converter=other_converter)
518+
519+
b1 = B(get_int)
520+
reveal_type(b1) # N: Revealed type is "__main__.B[builtins.int]"
521+
reveal_type(b1.x) # N: Revealed type is "__main__.Other[def (*Any, **Any) -> builtins.int]"
511522

512523
[builtins fixtures/list.pyi]
513524

0 commit comments

Comments
 (0)