You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use-case where i want to allow multiple different signature for methods when subclassing.
I've spend some time trying to make it pyright compliant and have discover some kind of weirdness.
from collections.abc import Callable
from typing import Self
type FuncSimple[T] = Callable[[T], int]
type Func[T] = Callable[[T], int] | Callable[[T, int], tuple[int, int]]
class Model:
f1: FuncSimple[Self]
f2: Func[Self]
class Example(Model):
def f1(self) -> int: return 1
def f2(self) -> int: return 1
pyright is fine if their is only one signature allowed (f1) but flags f2.
Is this normal behavior ? If so could someone explain to me what's happening :).
I've find a way to make pyright happy using CRTP pattern :
class Model2[T]:
f2:Func[T]
class Example2(Model2["Example2"]):
def f2(self) -> int: return 1
but if someone has something nicer i'll be glad.
I know it is a bit of a weird use case, my Model is some kind of dataclass (where some data are callables) that then get's normalized at class creation time.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a use-case where i want to allow multiple different signature for methods when subclassing.
I've spend some time trying to make it pyright compliant and have discover some kind of weirdness.
pyright is fine if their is only one signature allowed (f1) but flags f2.
Is this normal behavior ? If so could someone explain to me what's happening :).
I've find a way to make pyright happy using CRTP pattern :
but if someone has something nicer i'll be glad.
I know it is a bit of a weird use case, my
Modelis some kind of dataclass (where some data are callables) that then get's normalized at class creation time.Beta Was this translation helpful? Give feedback.
All reactions