Title: get_type_hints does not provide localns for classes
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, kj, larry, pbryan
Priority: normal Keywords: patch

Created on 2021-01-12 05:00 by pbryan, last changed 2021-04-13 09:48 by kj. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24201 merged kj, 2021-01-12 15:22
Messages (7)
msg384885 - (view) Author: Paul Bryan (pbryan) * Date: 2021-01-12 05:00
According to PEP 563:

> The get_type_hints() function automatically resolves the correct value of globalns for functions and classes. It also automatically provides the correct localns for classes.

This statement about providing correct localns for classes does not appear to be true.

Guido suggested this should be treated as a bug.
msg384887 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-12 05:12
Fidget-Spinner, are you interested in taking this?
msg384888 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-12 05:13
It's apparently a bug in all versions that support `from __future__ import annotations` (and only when that is used). Though perhaps we should only fix in in 3.10.
msg384925 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-01-12 12:33
> Fidget-Spinner, are you interested in taking this?

Sure thing! Please give me some time to look at it - I don't really use the runtime type validation stuff from typing (I usually defer that to 3rd party libraries), so I need to familiarize myself first.
msg390871 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-04-12 17:23
New changeset 852150ddfe68bc2696fc880175aeb855a0c16ae6 by Ken Jin in branch 'master':
bpo-42904: Fix get_type_hints for class local namespaces (GH-24201)
msg390872 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-04-12 17:24
Hi Ken Jin, you can close this issue now with your new permissions, right?
msg390945 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-04-13 09:48
Yup I can! BTW, I agree with keeping the change in 3.10 only. I suspect it _may_ be backwards-incompatible in small edge cases (re: the long comment on the PR about suspicions with local and global scope).
Date User Action Args
2021-04-13 09:48:40kjsetstatus: open -> closed
resolution: fixed
messages: + msg390945

stage: patch review -> resolved
2021-04-12 17:24:18gvanrossumsetmessages: + msg390872
2021-04-12 17:23:20gvanrossumsetmessages: + msg390871
2021-01-12 15:22:13kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23026
2021-01-12 12:33:43kjsetnosy: + kj
messages: + msg384925
2021-01-12 05:13:26gvanrossumsetmessages: + msg384888
2021-01-12 05:12:27gvanrossumsetmessages: + msg384887
2021-01-12 05:00:58pbryansetnosy: + larry
2021-01-12 05:00:15pbryancreate