Conversation
There was a problem hiding this comment.
No quality gates enabled for this code.
See analysis details in CodeScene
Quality Gate Profile: Custom Configuration
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
DrPaulSharp
left a comment
There was a problem hiding this comment.
Thanks for the detailed review notes, I'm inclined to agree that this approach is an improvement over what we have and should be accepted on that basis, with us keeping an eye on possible improvements down the line.
|
|
||
| import importlib | ||
| import os.path | ||
| import types |
There was a problem hiding this comment.
This line should be removed as the module is unused.
krzywon
left a comment
There was a problem hiding this comment.
Seems reasonable. The getattr suggestion is probably better in the long-term, but this is a step in the right direction.
Adding units.py to .gitignore can be a problem because the problem them becomes deciding when units.py gets generated.
Instead, I decided to punt on the issue by eliminating the autogenerated files entirely. Instead, the code is dynamically added to the modules at runtime. This means that the units module can never be out of sync and developers can't make changes that will be overwritten.
A couple of bits of advice for reviewing:
execis not a security concern here because it is not being called on untrusted strings. Any attacker attempting to produce a security hole here would need to be able to modify init.py or _units_base.py, which would already provide them all the privileges that they could have gained fromexec.The biggest disadvantage of this setup is that certain tools (e.g. MyPy) don't use the proper Python module loading system and do not see the members of the generated modules. I also fully concede that there might be a cleaner architecture through the use of
getattr, but that would be a significant rewrite and I thought that a smaller, incremental PR would be better at this time.Closes #199