Message326170
> See this for Yury's self-described "hack-ish fix we can use" until we do something better:
Actually, I think I found a better solution that doesn't require any changes to anything besides dataclasses.
Currently, dataclasses uses 'exec()' function to dynamically create methods like '__init__'. The generated code for '__init__' needs to access MISSING and _HAS_DEFAULT_FACTORY constants from the dataclasses module. To do that, we compile the code with 'exec()' with globals set to a dict with {MISSING, _HAS_DEFAULT_FACTORY} keys in it. This does the trick, but '__init__.__globals__' ends up pointing to that custom dict, instead of pointing to the module's dict.
The other way around is to use a closure around __init__ to inject MISSING and _HAS_DEFAULT_FACTORY values *and* to compile the code in a proper __dict__ of the module the dataclass was defined in. Please take a look at the PR. |
|
Date |
User |
Action |
Args |
2018-09-23 18:31:42 | yselivanov | set | recipients:
+ yselivanov, gvanrossum, ivan, eric.smith, lukasz.langa, drhagen |
2018-09-23 18:31:42 | yselivanov | set | messageid: <1537727502.57.0.956365154283.issue34776@psf.upfronthosting.co.za> |
2018-09-23 18:31:42 | yselivanov | link | issue34776 messages |
2018-09-23 18:31:42 | yselivanov | create | |
|