Skip to content

Conversation

@pkienzle
Copy link
Collaborator

@pkienzle pkienzle commented Jan 8, 2026

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.

Copy link
Collaborator

@krzywon krzywon left a 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"]
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positives with Pylance in VS Code

4 participants