Fix removed np.int alias in nstates return annotation - #52
Open
rayair250-droid wants to merge 1 commit into
Open
Fix removed np.int alias in nstates return annotation#52rayair250-droid wants to merge 1 commit into
rayair250-droid wants to merge 1 commit into
Conversation
np.int was removed in NumPy 1.24, and the project pins numpy<2, so no supported NumPy version defines it. nstates returns len(self.electronic_states), a builtin int, so the annotation was also semantically wrong. It is currently masked only because 'from __future__ import annotations' makes annotations lazy strings, but typing.get_type_hints() on this class would raise AttributeError. This is the only such deprecated alias left in the codebase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mlatom/data.pyannotates thenstatesproperty with the removed aliasnp.int:np.intwas deprecated in NumPy 1.20 and removed in NumPy 1.24. Sincepyproject.tomlpinsnumpy<2, every supported NumPy (1.24–1.26) lacks this attribute. The property returnslen(self.electronic_states)— a builtinint— so the annotation was also semantically incorrect.It doesn't crash on import only because
from __future__ import annotationsmakes annotations lazy strings, but anytyping.get_type_hints()on this class raisesAttributeError: module 'numpy' has no attribute 'int'.Fix
One-line, behavior-preserving. This is the only remaining deprecated NumPy alias (
np.int/np.float/np.bool/np.object) in the codebase.