Skip to content
This repository has been archived by the owner on Dec 27, 2021. It is now read-only.

Commit

Permalink
fix(typing): allow any object as first argument for get_type_hints (p…
Browse files Browse the repository at this point in the history
…ython#4744)

get_type_hints works on more object

Fixes python#4678
  • Loading branch information
jd authored Nov 12, 2020
1 parent 2949a92 commit 6701e74
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions stdlib/3/typing.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
from abc import ABCMeta, abstractmethod
from types import CodeType, FrameType, TracebackType
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType

if sys.version_info >= (3, 7):
from types import MethodDescriptorType, MethodWrapperType, WrapperDescriptorType

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand Down Expand Up @@ -585,17 +588,41 @@ class Pattern(Generic[AnyStr]):

# Functions

if sys.version_info >= (3, 7):
_get_type_hints_obj_allowed_types = Union[
object,
Callable[..., Any],
FunctionType,
BuiltinFunctionType,
MethodType,
ModuleType,
WrapperDescriptorType,
MethodWrapperType,
MethodDescriptorType,
]
else:
_get_type_hints_obj_allowed_types = Union[
object,
Callable[..., Any],
FunctionType,
BuiltinFunctionType,
MethodType,
ModuleType,
]

if sys.version_info >= (3, 9):
def get_type_hints(
obj: Callable[..., Any],
obj: _get_type_hints_obj_allowed_types,
globalns: Optional[Dict[str, Any]] = ...,
localns: Optional[Dict[str, Any]] = ...,
include_extras: bool = ...,
) -> Dict[str, Any]: ...

else:
def get_type_hints(
obj: Callable[..., Any], globalns: Optional[Dict[str, Any]] = ..., localns: Optional[Dict[str, Any]] = ...
obj: _get_type_hints_obj_allowed_types,
globalns: Optional[Dict[str, Any]] = ...,
localns: Optional[Dict[str, Any]] = ...,
) -> Dict[str, Any]: ...

if sys.version_info >= (3, 8):
Expand Down

0 comments on commit 6701e74

Please sign in to comment.