This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients arne, eric.smith, levkivskyi
Date 2019-10-28.16:16:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1572279417.21.0.734134208431.issue37948@roundup.psfhosted.org>
In-reply-to
Content
I'm not sure what can be done with this. The problem is that the decorator doesn't know what's in the caller's namespace. The type being added is "typing.Any". If the caller doesn't import typing, then get_type_hints will fail (as demonstrated here).

The only thing I can think of is using a type that's in builtins. "object" springs to mine, but of course that's semantically incorrect.

Or, maybe I could use "dataclasses.sys.modules['typing'].Any". I don't currently import sys (I don't think), but this should be a cheap import. Then if typing.get_type_hints() is called, we know typing will have already been importing.

But what if "dataclasses" isn't in the caller's namespace? I guess if I could find some way to navigate to sys.modules from __builtins__, that would largely work, absent playing games with builtins.
History
Date User Action Args
2019-10-28 16:16:57eric.smithsetrecipients: + eric.smith, levkivskyi, arne
2019-10-28 16:16:57eric.smithsetmessageid: <1572279417.21.0.734134208431.issue37948@roundup.psfhosted.org>
2019-10-28 16:16:57eric.smithlinkissue37948 messages
2019-10-28 16:16:56eric.smithcreate