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

assigning a class with __call__ to dunder method shows the wrong type #9470

Closed
adhami3310 opened this issue Nov 15, 2024 · 3 comments
Closed
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@adhami3310
Copy link

adhami3310 commented Nov 15, 2024

from typing_extensions import Self, reveal_type


class Function:
    def __call__(self, *args, **kwargs) -> Self:
        return self


class ArrayLike:
    __getitem__ = Function()


x = ArrayLike()[0]
reveal_type(x) # Type of "x" is "ArrayLike"
print(type(x))

but prints: <class '__main__.Function'>, as self is Function. This doesn't feel like intended behavior.

I'm using pyright 1.1.389.

@adhami3310 adhami3310 added the bug Something isn't working label Nov 15, 2024
@adhami3310
Copy link
Author

Interestingly, x = ArrayLike().__getitem__(0) does show x: Function. So there's a discrepancy, even though the two are equivalent.

@adhami3310
Copy link
Author

erictraut added a commit that referenced this issue Nov 29, 2024
…` is set to a callable object. This addresses #9470.
erictraut added a commit that referenced this issue Nov 29, 2024
…` is set to a callable object. This addresses #9470. (#9519)
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Nov 29, 2024
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.390.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants