We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
from __future__ import annotations from typing_extensions import Self, TypeVar, overload, reveal_type, TypeVarTuple S = TypeVar("S") R = TypeVarTuple("R") class Function[*T]: def __init__(self, *prefilled_args): self.prefilled_args = prefilled_args def __call__(self, *args: *T) -> None: print(f"{self.prefilled_args + args=}") def partial_once[S, *R](self: Function[S, *R], arg: S) -> Function[*R]: return Function(*self.prefilled_args, arg) @overload def __get__(self, instance: None, owner) -> Self: ... @overload def __get__(self: Function[S, *R], instance: S, owner) -> Function[*R]: ... def __get__(self, instance, owner): if instance is None: return self return self.partial_once(instance) class ArrayLike: __add__ = Function[Self, int]() x = ArrayLike().__add__(1) y = ArrayLike() + 1
Some of the code here is a bit much, but I wanted to illustrate some form of useful code that would use such functionality.
Both calls succeed just fine in runtime with the expected output:
self.prefilled_args + args=(<__main__.ArrayLike object at 0x7f2c575370e0>, 1)
Yet Pyright errors:
error: Operator "+" not supported for types "ArrayLike" and "Literal[1]" (reportOperatorIssue)
only for the second one.
It seems when using dunder methods, pyright is not evaluating the get in the type checking.
MyPy fails both which I assume is more related to using TypeVarTuple, but Pyright seems to handle that better.
Note in the example above we have another typing error at self.partial_once(instance) but that one is correctly caught.
self.partial_once(instance)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Some of the code here is a bit much, but I wanted to illustrate some form of useful code that would use such functionality.
Both calls succeed just fine in runtime with the expected output:
Yet Pyright errors:
only for the second one.
It seems when using dunder methods, pyright is not evaluating the get in the type checking.
MyPy fails both which I assume is more related to using TypeVarTuple, but Pyright seems to handle that better.
Note in the example above we have another typing error at
self.partial_once(instance)
but that one is correctly caught.The text was updated successfully, but these errors were encountered: