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

Issue with mypy and __getitem__() for all Vec* types #12

Open
romainf-ubi opened this issue Oct 4, 2024 · 0 comments
Open

Issue with mypy and __getitem__() for all Vec* types #12

romainf-ubi opened this issue Oct 4, 2024 · 0 comments

Comments

@romainf-ubi
Copy link

romainf-ubi commented Oct 4, 2024

Hi!

I have a bug with mypy when dealing with Gf.Vec3f type.

What's happening

If you write this code:

from pxr import Gf

v = Gf.Vec3f(1.0, 2.0, 3.0)
dimensions: list[float] = [ v[0], v[1], v[2] ]

You'll get these errors:

$ py -m mypy .
my.py:4: error: List item 0 has incompatible type "list[Any]"; expected "float"  [list-item]
my.py:4: error: List item 1 has incompatible type "list[Any]"; expected "float"  [list-item]
my.py:4: error: List item 2 has incompatible type "list[Any]"; expected "float"  [list-item]
Found 3 errors in 1 file (checked 1 source file)

The same happens with Vec3h, Vec2f, Vec3i, etc...

Expected behavior

mypy should not raise errors.

Reason

The issue (for Vec3f) comes from usd/stubs/pxr/Gf/__init__.pyi at lines lines 6715 to 6720:

    @overload
    def __getitem__(self, _i: int, /) -> list:
        """
        Indexing.
        """
    @overload
    def __getitem__(self, arg2: int, /) -> float: ...

Both __getitem__ methods have the exact same signature (i.e. (self, int)) but return different types: list and float

Workaround

Add # type: ignore [list-item] at the end of the line with the error

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

No branches or pull requests

1 participant