diff options
| author | Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> | 2021-04-13 01:23:12 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-12 10:23:12 -0700 |
| commit | 852150ddfe68bc2696fc880175aeb855a0c16ae6 (patch) | |
| tree | d4cd9bfcff32cb08f7bcdcf51d46bb82b45de397 /Lib/typing.py | |
| parent | 37a5e220234dd4afb8f97b810393e3d58db674a1 (diff) | |
| download | cpython-git-852150ddfe68bc2696fc880175aeb855a0c16ae6.tar.gz | |
bpo-42904: Fix get_type_hints for class local namespaces (GH-24201)
Diffstat (limited to 'Lib/typing.py')
| -rw-r--r-- | Lib/typing.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index a24c01f0e3..583438e474 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -1632,12 +1632,13 @@ def get_type_hints(obj, globalns=None, localns=None, include_extras=False): else: base_globals = globalns ann = base.__dict__.get('__annotations__', {}) + base_locals = dict(vars(base)) if localns is None else localns for name, value in ann.items(): if value is None: value = type(None) if isinstance(value, str): value = ForwardRef(value, is_argument=False) - value = _eval_type(value, base_globals, localns) + value = _eval_type(value, base_globals, base_locals) hints[name] = value return hints if include_extras else {k: _strip_annotations(t) for k, t in hints.items()} |
