Skip to content
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

Remove TopologyAtom from docstrings, add some annotations #1584

Merged
merged 3 commits into from Apr 20, 2023

Conversation

mattwthompson
Copy link
Member

@mattwthompson mattwthompson commented Apr 18, 2023

def atom(self, atom_topology_index):
def atom(self, atom_topology_index: int) -> "Atom":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change I care about. The current code has this unfortunate downstream behavior:

from openff.toolkit import Molecule

topology = Molecule.from_smiles("CCO").to_topology()

reveal_type(topology.atom(0).atomic_number)
$ mypy j.py
j.py:5: note: Revealed type is "Any"
Success: no issues found in 1 source file

Alone this is not the end of the world but Atom is often a launching point for much more information. The case I ran into was a type checker thinking that

        atomic_numbers: tuple[int, ...] = tuple(
            a.atomic_number for a in interchange.topology.atoms
        )

was actually tuple[Any]

Comment on lines +2497 to +2500
raise AtomNotInTopologyError(
f"No atom with index {atom_topology_index} exists in this topology, "
f"which contains {self.n_atoms} atoms."
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function's logic has an expression after the return statement, which confused the type checker. I threw this in not because it should ever be hit, but maybe it's possible.

@codecov
Copy link

codecov bot commented Apr 18, 2023

Codecov Report

Merging #1584 (ff074ad) into main (8c7bf90) will decrease coverage by 0.24%.
The diff coverage is 75.00%.

Additional details and impacted files

Copy link
Member

@j-wags j-wags left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the update :-)

@j-wags
Copy link
Member

j-wags commented Apr 20, 2023

I see this isn't marked "Ready for review" but IMO this is mergeable in its current state (only other thing I could think of is releasenotes, but that's not a blocker). Please merge when you're ready!

@mattwthompson mattwthompson marked this pull request as ready for review April 20, 2023 22:31
@mattwthompson
Copy link
Member Author

My oversight - I was unsure if the added exception block was too ugly to get through, but that's the opposite of not asking for feedback 🙃

@mattwthompson
Copy link
Member Author

Thanks for the review - and allowing me to do something ugly in the advancement of non-ugly things

@mattwthompson mattwthompson merged commit beb5579 into main Apr 20, 2023
17 of 18 checks passed
@mattwthompson mattwthompson deleted the more-annotations branch April 20, 2023 22:54
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.

None yet

2 participants