"""
from typing import Optional
+from functools import wraps
__annotations__[1] = 2
def bar(y: List[str]):
x: str = 'yes'
bar()
+
+def dec(func):
+ @wraps(func)
+ def wrapper(*args, **kwargs):
+ return func(*args, **kwargs)
+ return wrapper
gth = get_type_hints
+class ForRefExample:
+ @ann_module.dec
+ def func(self: 'ForRefExample'):
+ pass
+
+ @ann_module.dec
+ @ann_module.dec
+ def nested(self: 'ForRefExample'):
+ pass
+
class GetTypeHintTests(BaseTestCase):
def test_get_type_hints_from_various_objects(self):
'x': ClassVar[Optional[B]]})
self.assertEqual(gth(G), {'lst': ClassVar[List[T]]})
+ def test_get_type_hints_wrapped_decoratored_func(self):
+ expects = {'self': ForRefExample}
+ self.assertEqual(gth(ForRefExample.func), expects)
+ self.assertEqual(gth(ForRefExample.nested), expects)
+
class CollectionsAbcTests(BaseTestCase):
if isinstance(obj, types.ModuleType):
globalns = obj.__dict__
else:
- globalns = getattr(obj, '__globals__', {})
+ nsobj = obj
+ # Find globalns for the unwrapped object.
+ while hasattr(nsobj, '__wrapped__'):
+ nsobj = nsobj.__wrapped__
+ globalns = getattr(nsobj, '__globals__', {})
if localns is None:
localns = globalns
elif localns is None:
--- /dev/null
+:meth:`typing.get_type_hints` properly handles functions decorated with :meth:`functools.wraps`.