-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for converters with TypeVars on generic attrs classes (#1…
…4908) 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.
- Loading branch information
Showing
2 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters