From 50c71883000f14ae0bfe622906d3fc4ba1e29875 Mon Sep 17 00:00:00 2001 From: David Euresti Date: Mon, 5 Mar 2018 19:21:14 -0800 Subject: [PATCH] Work around mypy issue #4554 in attr.Factory (#1933) This makes the following not give a type error: y: DefaultDict[str, List[int]] = Factory(lambda: defaultdict(list)) --- third_party/2and3/attr/__init__.pyi | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/attr/__init__.pyi b/third_party/2and3/attr/__init__.pyi index 56641ead4..e4961491e 100644 --- a/third_party/2and3/attr/__init__.pyi +++ b/third_party/2and3/attr/__init__.pyi @@ -21,7 +21,11 @@ _ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]] NOTHING: object # NOTE: Factory lies about its return type to make this possible: `x: List[int] = Factory(list)` -def Factory(factory: Union[Callable[[], _T], Callable[[Any], _T]], takes_self: bool = ...) -> _T: ... +# Work around mypy issue #4554 by using an overload vs a Union. +@overload +def Factory(factory: Callable[[], _T], takes_self: bool = ...) -> _T: ... +@overload +def Factory(factory: Callable[[Any], _T], takes_self: bool = ...) -> _T: ... class Attribute(Generic[_T]): name: str