Skip to content

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

@Saransh-cpp

Description

@Saransh-cpp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe problem described is something that must be fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions