diff --git a/stdlib/@python2/__builtin__.pyi b/stdlib/@python2/__builtin__.pyi index b7b68bbb7844..0b2c89e8d80c 100644 --- a/stdlib/@python2/__builtin__.pyi +++ b/stdlib/@python2/__builtin__.pyi @@ -863,9 +863,14 @@ def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> List[_T def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode @overload def getattr(__o: Any, name: Text) -> Any: ... + +# While technically covered by the last overload, spelling out the types for None and bool +# help mypy out in some tricky situations involving type context (aka bidirectional inference) @overload def getattr(__o: Any, name: Text, __default: None) -> Optional[Any]: ... @overload +def getattr(__o: Any, name: Text, __default: bool) -> Union[Any, bool]: ... +@overload def getattr(__o: Any, name: Text, __default: _T) -> Union[Any, _T]: ... def globals() -> Dict[str, Any]: ... def hasattr(__obj: Any, __name: Text) -> bool: ... diff --git a/stdlib/@python2/builtins.pyi b/stdlib/@python2/builtins.pyi index b7b68bbb7844..0b2c89e8d80c 100644 --- a/stdlib/@python2/builtins.pyi +++ b/stdlib/@python2/builtins.pyi @@ -863,9 +863,14 @@ def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> List[_T def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode @overload def getattr(__o: Any, name: Text) -> Any: ... + +# While technically covered by the last overload, spelling out the types for None and bool +# help mypy out in some tricky situations involving type context (aka bidirectional inference) @overload def getattr(__o: Any, name: Text, __default: None) -> Optional[Any]: ... @overload +def getattr(__o: Any, name: Text, __default: bool) -> Union[Any, bool]: ... +@overload def getattr(__o: Any, name: Text, __default: _T) -> Union[Any, _T]: ... def globals() -> Dict[str, Any]: ... def hasattr(__obj: Any, __name: Text) -> bool: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 865c6e9a12d7..8b45df95a266 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1021,9 +1021,14 @@ class filter(Iterator[_T], Generic[_T]): def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode @overload def getattr(__o: Any, name: str) -> Any: ... + +# While technically covered by the last overload, spelling out the types for None and bool +# help mypy out in some tricky situations involving type context (aka bidirectional inference) @overload def getattr(__o: Any, name: str, __default: None) -> Optional[Any]: ... @overload +def getattr(__o: Any, name: str, __default: bool) -> Union[Any, bool]: ... +@overload def getattr(__o: Any, name: str, __default: _T) -> Union[Any, _T]: ... def globals() -> Dict[str, Any]: ... def hasattr(__obj: Any, __name: str) -> bool: ...