Skip to content

Fix removed np.int alias in nstates return annotation#52

Open
rayair250-droid wants to merge 1 commit into
dralgroup:mainfrom
rayair250-droid:fix/np-int-removed-alias
Open

Fix removed np.int alias in nstates return annotation#52
rayair250-droid wants to merge 1 commit into
dralgroup:mainfrom
rayair250-droid:fix/np-int-removed-alias

Conversation

@rayair250-droid

Copy link
Copy Markdown
Contributor

Summary

mlatom/data.py annotates the nstates property with the removed alias np.int:

@property
def nstates(self) -> np.int:

np.int was deprecated in NumPy 1.20 and removed in NumPy 1.24. Since pyproject.toml pins numpy<2, every supported NumPy (1.24–1.26) lacks this attribute. The property returns len(self.electronic_states) — a builtin int — so the annotation was also semantically incorrect.

It doesn't crash on import only because from __future__ import annotations makes annotations lazy strings, but any typing.get_type_hints() on this class raises AttributeError: module 'numpy' has no attribute 'int'.

Fix

-    def nstates(self) -> np.int:
+    def nstates(self) -> int:

One-line, behavior-preserving. This is the only remaining deprecated NumPy alias (np.int/np.float/np.bool/np.object) in the codebase.

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.
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.

1 participant