Make types-networkx NumPy dependency optional - #16297
Conversation
OpenAI Codex assisted with issue review, implementation, and verification. The change was reviewed before submission.
| # requires a version of numpy with a `py.typed` file | ||
| dependencies = ["numpy>=1.20"] | ||
| optional-dependencies = ["numpy>=1.20"] |
There was a problem hiding this comment.
networkx requires numpy>=2 nowadays: https://github.com/networkx/networkx/blob/8e0b38e1a11335f07db13a13a6a5955eecf33408/pyproject.toml#L71
So maybe it's an idea to also update that here.
There was a problem hiding this comment.
Thanks for pointing this out. I checked both the released dependency and the typing API used by these stubs. This PR targets NetworkX 3.6.1, whose released default extra uses NumPy >=1.25; >=2 is currently only on unreleased main. For the typeshed metadata floor, the stubs import numpy.typing.NDArray, which was introduced in NumPy 1.21, matching the existing approach in #13538. I have therefore raised the optional dependency to >=1.21 in 142ce78. I am happy to adjust further if the maintainers prefer this extra to mirror the NetworkX runtime floor instead.
The stubs import numpy.typing.NDArray, which was introduced in NumPy 1.21. Keep the optional dependency aligned with the minimum typing API the stubs use rather than an unreleased NetworkX requirement. OpenAI Codex assisted with review, implementation, and verification. The change was reviewed before submission.
Fixes #14760
Move NumPy from the required stub dependency list to
optional-dependencies. This keeps pure graph users from installing NumPy transitively while retaining a discoverablenumpyextra for users of NumPy-backed APIs.Use NumPy 1.21 as the optional dependency floor because these stubs import
numpy.typing.NDArray, which was introduced in 1.21. Thenumpy>=2requirement discussed in review is currently on unreleased NetworkX main; this PR targets NetworkX 3.6.1.Validation:
python tests/check_typeshed_structure.pypython tests/get_external_stub_requirements.py networkxpre-commit run --files stubs/networkx/METADATA.tomlAgent used: OpenAI Codex.