Message355559
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. |
|
Date |
User |
Action |
Args |
2019-10-28 16:16:57 | eric.smith | set | recipients:
+ eric.smith, levkivskyi, arne |
2019-10-28 16:16:57 | eric.smith | set | messageid: <1572279417.21.0.734134208431.issue37948@roundup.psfhosted.org> |
2019-10-28 16:16:57 | eric.smith | link | issue37948 messages |
2019-10-28 16:16:56 | eric.smith | create | |
|