Skip to content

fix(typing): preserve concrete backend return types for to_Vector*D and to_*D (#642) - #767

Open
Hiak-Harsha wants to merge 1 commit into
scikit-hep:mainfrom
Hiak-Harsha:fix-to-vector-return-types
Open

Hiak-Harsha wants to merge 1 commit into
scikit-hep:mainfrom
Hiak-Harsha:fix-to-vector-return-types

Conversation

@Hiak-Harsha

Copy link
Copy Markdown

Fixes #642.

Summary

Calling o_Vector2D(), o_Vector3D(), o_Vector4D(), o_2D(), o_3D(), or o_4D() on concrete Object or NumPy vector/momentum classes (MomentumObject4D, VectorObject4D, MomentumNumpy4D, etc.) previously inherited the base VectorProtocolPlanar / VectorProtocolSpatial / VectorProtocolLorentz return annotations from �ector._methods. As a result, static type checkers (mypy, pyright) rejected passing �ec.to_Vector3D() to functions expecting MomentumObject3D.

This PR adds if typing.TYPE_CHECKING: method signature refinements on VectorObjectD, MomentumObjectD, VectorNumpyD, and MomentumNumpyD so type checkers preserve the exact concrete backend and momentum/vector class across dimension projections without affecting runtime behavior.

Verification

This branch has not been deployed

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

User-facing type annotations don't work for to_Vector*D methods

1 participant