-
Notifications
You must be signed in to change notification settings - Fork 37
Add type hinting #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add type hinting #109
Conversation
krzywon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my inline comments for a few suggestions. For more global comments, I noted the first instance of that suggestion, but no others.
|
|
||
| from . import constants | ||
|
|
||
| Atom = Union["Element", "Isotope", "Ion"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.python.org/3/library/typing.html#typing.Union says the shorthand "Element" | "Isotope" | "Ion" is recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are strings. The or operator doesn't know how to turn them into types. This is fixed in the latest python (no need for quotes for as-yet-undefined types) but not yet in the supported older versions.
Adds support for type hinting which works in VScode. Fixes #104
Fixes the natural mass ratio calculation for compounds containing ionized isotopes. The old version was delegating from Ion to Isotope rather than Ion to Element for the natural density.
mypy still reports many errors. Most are from the use of None instead of NaN for undefined values. Type hinting and processing much more complicated to do correctly when you need to handle union of None and float. I'm not going to fix these are part of this PR.
There are warning about the assignment of properties to attributes which arise because of delayed loading of attributes. These are also out of scope.
My VSCode session feels laggy now that I have substantial type hinting coverage. We may need to trim back completeness in the interest of speed. Types like numpy ArrayLike require lots of inference.