mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
builtins: add a getattr overload for bool (#5518)
As brought up in https://github.com/python/typeshed/pull/5516 Alternatives include: - Use another type var that has a value restriction - Doing something fancy with Protocols that have a __bool__ that returns a Literal (which may not work) - Doing nothing
This commit is contained in:
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user