scikit-hep / scikit-hep/vector

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

Open
#642 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
99
Forks
42
Avg merge
1d 13h
Merged PRs (30d)
6

Description

Originally posted by acampove September 22, 2025 in #640

This is the MWE

import vector
from vector import MomentumObject3D

def _fun(vec : MomentumObject3D) -> None:
    print(vec)

vec = vector.obj(pt=1.0, eta=1.0, phi=1.0, mass=10)
v3d = vec.to_Vector3D()

_fun(vec=v3d)

save it, run pyright/mypy test.py and you will see:

(rx) [acampove@thinkbook vector]$ pyright test.py
WARNING: there is a new pyright version available (v1.1.404 -> v1.1.405).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`

/home/acampove/Tests/vector/test.py
  /home/acampove/Tests/vector/test.py:10:10 - error: Argument of type "VectorProtocolSpatial" cannot be assigned to parameter "vec" of type "MomentumObject3D" in function "_fun"
    "VectorProtocolSpatial" is not assignable to "MomentumObject3D" (reportArgumentType)
1 error, 0 warnings, 0 informations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the type definitions behind vector.obj and its to_Vector3D method, then reproduce the issue from the Python example using pyright or mypy. Done means the returned value is accepted as MomentumObject3D in the shown _fun call without the reported type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.