summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-04-21 11:41:19 (GMT)
committerGitHub <noreply@github.com>2021-04-21 11:41:19 (GMT)
commitb0544ba77cf86074fb1adde00558c67ca75eeea1 (patch)
tree5168d0dc8da1360feabecfbc7c721b3fa9a38b11 /Lib/inspect.py
parentd35eef3b904b62e9c775bf3764ab0a0611f5a860 (diff)
downloadcpython-b0544ba77cf86074fb1adde00558c67ca75eeea1.zip
cpython-b0544ba77cf86074fb1adde00558c67ca75eeea1.tar.gz
cpython-b0544ba77cf86074fb1adde00558c67ca75eeea1.tar.bz2
bpo-38605: Revert making 'from __future__ import annotations' the default (GH-25490)
This reverts commits 044a1048ca93d466965afc027b91a5a9eb9ce23c and 1be456ae9d53bb1cba2b24fc86175c282d1c2169, adapting the code to changes that happened after it.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py19
1 files changed, 2 insertions, 17 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index d6d2ce6..b8e247e 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -45,7 +45,6 @@ import sys
import tokenize
import token
import types
-import typing
import warnings
import functools
import builtins
@@ -1893,10 +1892,7 @@ def _signature_is_functionlike(obj):
code = getattr(obj, '__code__', None)
defaults = getattr(obj, '__defaults__', _void) # Important to use _void ...
kwdefaults = getattr(obj, '__kwdefaults__', _void) # ... and not None here
- try:
- annotations = _get_type_hints(obj)
- except AttributeError:
- annotations = None
+ annotations = getattr(obj, '__annotations__', None)
return (isinstance(code, types.CodeType) and
isinstance(name, str) and
@@ -2137,16 +2133,6 @@ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
return cls(parameters, return_annotation=cls.empty)
-def _get_type_hints(func, **kwargs):
- try:
- return typing.get_type_hints(func, **kwargs)
- except Exception:
- # First, try to use the get_type_hints to resolve
- # annotations. But for keeping the behavior intact
- # if there was a problem with that (like the namespace
- # can't resolve some annotation) continue to use
- # string annotations
- return func.__annotations__
def _signature_from_builtin(cls, func, skip_bound_arg=True):
"""Private helper function to get signature for
@@ -2191,8 +2177,7 @@ def _signature_from_function(cls, func, skip_bound_arg=True,
positional = arg_names[:pos_count]
keyword_only_count = func_code.co_kwonlyargcount
keyword_only = arg_names[pos_count:pos_count + keyword_only_count]
- annotations = _get_type_hints(func, globalns=globalns, localns=localns)
-
+ annotations = func.__annotations__
defaults = func.__defaults__
kwdefaults = func.__kwdefaults__