Open michaellisitsa opened 3 years ago
Hi @michaellisitsa,
Thank you for bringing this up and directing me to the stackoverflow link. This is a known issue (for me) with forallpeople. It looks like this can be fixed with the __set_attr__
thing. I think there is a way to make this work...
@michaellisitsa
I think this may have been fixed in VS Code. Have you noticed a change?
it may have been fixed in vs code, but this issue persists with pycharm
The units imported imported into builtins appear not to be recognised by mypy language server (used in Pylance extension in VS Code) and gives errors depending on the strictness of your type checking.
Given the dynamic setting of builtin functions from the json file, this may not be possible to fix, but thought maybe there is some fixes you have in mind.
At the moment I'm using
but that is line by line so not very elegant. There is some discussion of using a
__setattr__
dunder method on the below link that allows any inputs, but I don't quite understand if that would block any type hints whatsoever for the class its applied to for other methods like.environment()
or.to()
, which might defeat the whole purpose of having type hints. https://stackoverflow.com/questions/50889677/remove-error-from-mypy-for-attributes-set-dynamically-in-a-python-classIt appears the below inside environments.py is where the
__setattr__
occurs depending on thephysical_class
inputted e.g.u.environment("structural")
the units are read from the json files and pushed to builtins.Because the code isn't evaluated until runtime, then Pylance would not know about what variables will be created.
How to reproduce
m
orkN
"m" is not a known member of module