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

Improve type annotations for core.structure #3837

Merged
merged 18 commits into from
May 25, 2024

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented May 17, 2024

Summary

  • Improve type annotations for core.structure
  • Fix some type: ignore[reportPossiblyUnboundVariable]

A question from me:

What is the difference between np.ndarray, ArrayLike and NDArray for typing?

ArrayLike: type[Buffer] | type[_SupportsArray[dtype[Any]]] | type[_NestedSequence[_SupportsArray[dtype[Any]]]] | type[bool] | type[int] | type[float] | type[complex] | type[str] | type[bytes] | type[_NestedSequence[bool | int | float | complex | str | bytes]]

NDArray: type[ndarray[Any, dtype[_ScalarType_co@NDArray]]]

@DanielYang59 DanielYang59 marked this pull request as ready for review May 24, 2024 12:02
@DanielYang59
Copy link
Contributor Author

@janosh Can you please review this? Thanks.

Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks @DanielYang59! 👍

@janosh janosh enabled auto-merge (squash) May 25, 2024 07:43
@DanielYang59
Copy link
Contributor Author

Thanks for reviewing and the tweaks!

@janosh janosh merged commit d0ad785 into materialsproject:master May 25, 2024
23 checks passed
@DanielYang59 DanielYang59 deleted the types-core-structure branch May 25, 2024 07:54
@janosh janosh added linting Linting and quality assurance types Type all the things labels May 31, 2024
@wortelboer
Copy link

Hello,
Today I ran into an issue while using pymatgen 2024.5.31, that I think might be related to this contribution. I am using a fresh conda environment, python 3.11, with pymatgen installed via pip install pymatgen. I get an error when trying to import from pymatgen.core.structure:

>>> from pymatgen.core import Structure
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~\AppData\Local\miniconda3\envs\test311\Lib\site-packages\pymatgen\core\__init__.py", line 17, in <module>
    from pymatgen.core.structure import IMolecule, IStructure, Molecule, PeriodicNeighbor, SiteCollection, Structure
  File "~\AppData\Local\miniconda3\envs\test311\Lib\site-packages\pymatgen\core\structure.py", line 39, in <module>
    from typing_extensions import Self
ModuleNotFoundError: No module named 'typing_extensions'

If I then install typing-extensions separately, things seem to work fine. In v2024.5.31's setup.py I see that typing-extensions is listed under extras_require["dev"]. My understanding of setup.py is limited though. Should I install pymatgen in a different way?
Thank you in advance.

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Jun 4, 2024

Hi @wortelboer thanks for asking and sorry for the trouble caused, I forgot to guard a typing_extensions import, and I'm asking Shyue to yank current release and issue a new one to fix this. You could manually install typing-extensions for now, until a new release is up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linting Linting and quality assurance types Type all the things
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants