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
Add support for converters with TypeVars on generic attrs classes (#14908)
When creating generic classes using `attrs`, converters with type vars
are not properly integrated into the generated `__init__`:
```python
from typing import TypeVar, Generic, List, Iterable, Iterator
import attr
T = TypeVar('T')
def int_gen() -> Iterator[int]:
yield 1
def list_converter(x: Iterable[T]) -> List[T]:
return list(x)
@attr.s(auto_attribs=True)
class A(Generic[T]):
x: List[T] = attr.ib(converter=list_converter)
y: T = attr.ib()
a1 = A([1], 2) # E: Argument 1 to "A" has incompatible type "Iterator[int]"; expected "Iterable[T]"
```
This MR fixes the bug by copying type vars from the field/attrib into
the type extracted from the converter.
0 commit comments