|
45 | 45 | import tokenize |
46 | 46 | import token |
47 | 47 | import types |
48 | | -import typing |
49 | 48 | import warnings |
50 | 49 | import functools |
51 | 50 | import builtins |
@@ -1893,10 +1892,7 @@ def _signature_is_functionlike(obj): |
1893 | 1892 | code = getattr(obj, '__code__', None) |
1894 | 1893 | defaults = getattr(obj, '__defaults__', _void) # Important to use _void ... |
1895 | 1894 | kwdefaults = getattr(obj, '__kwdefaults__', _void) # ... and not None here |
1896 | | - try: |
1897 | | - annotations = _get_type_hints(obj) |
1898 | | - except AttributeError: |
1899 | | - annotations = None |
| 1895 | + annotations = getattr(obj, '__annotations__', None) |
1900 | 1896 |
|
1901 | 1897 | return (isinstance(code, types.CodeType) and |
1902 | 1898 | isinstance(name, str) and |
@@ -2137,16 +2133,6 @@ def p(name_node, default_node, default=empty): |
2137 | 2133 |
|
2138 | 2134 | return cls(parameters, return_annotation=cls.empty) |
2139 | 2135 |
|
2140 | | -def _get_type_hints(func, **kwargs): |
2141 | | - try: |
2142 | | - return typing.get_type_hints(func, **kwargs) |
2143 | | - except Exception: |
2144 | | - # First, try to use the get_type_hints to resolve |
2145 | | - # annotations. But for keeping the behavior intact |
2146 | | - # if there was a problem with that (like the namespace |
2147 | | - # can't resolve some annotation) continue to use |
2148 | | - # string annotations |
2149 | | - return func.__annotations__ |
2150 | 2136 |
|
2151 | 2137 | def _signature_from_builtin(cls, func, skip_bound_arg=True): |
2152 | 2138 | """Private helper function to get signature for |
@@ -2191,8 +2177,7 @@ def _signature_from_function(cls, func, skip_bound_arg=True, |
2191 | 2177 | positional = arg_names[:pos_count] |
2192 | 2178 | keyword_only_count = func_code.co_kwonlyargcount |
2193 | 2179 | keyword_only = arg_names[pos_count:pos_count + keyword_only_count] |
2194 | | - annotations = _get_type_hints(func, globalns=globalns, localns=localns) |
2195 | | - |
| 2180 | + annotations = func.__annotations__ |
2196 | 2181 | defaults = func.__defaults__ |
2197 | 2182 | kwdefaults = func.__kwdefaults__ |
2198 | 2183 |
|
|
0 commit comments