ericvsmith/dataclasses#92 (comment) raised an important question (this existing problem is also mentioned in PEP 563). Currently, get_type_hints will raise a NameError in situations where it might not be the desired behaviour (e.g. if used by a class decorator). For example:
defmodify(cls):
types=get_type_hints(cls)
# do something with 'cls' and 'types'returncls@modifyclassC:
linked: 'C'
It looks like it will be useful to have an option to keep forward references that are currently undefined. For example:
Activity
gvanrossum commented on Dec 4, 2017
djrochford commented on Apr 17, 2019
I take it this was not easy to fix? I, for one, would be very glad to see this fixed, but I gather that's unlikely to happen soon...
ilevkivskyi commented on Apr 17, 2019
This is not easy, but not too hard either. I just didn't have time for this, sorry.
djrochford commented on Apr 17, 2019
Oh, no need to apologise! I commented only in the hope of bumping this slightly higher the priority list, but I'll survive, and life is short.
The-Compiler commented on Apr 16, 2021
A somewhat related Python bug I've opened about this a couple of weeks ago (before finding this issue): Issue 43463: typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument - Python tracker
srittau commented on Nov 4, 2021
Please report this bug to bugs.python.org if it still exists.