-
The following snippet: from __future__ import annotations
import dataclasses
class Foo:
def bark(self) -> Jee:
return self
@dataclasses.dataclass(slots=True, frozen=True)
class Bar[T: Jee]: # T is clearly a Jee.
meow: T
def bark(self) -> Jee:
return self # error
type Jee = Foo | Bar[Jee] causes Pyright to report the following:
I am confused. Am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Pyright's behavior here is correct. (Not surprisingly, mypy generates the same error in this case.) You haven't provided a type annotation for the |
Beta Was this translation helpful? Give feedback.
Pyright's behavior here is correct. (Not surprisingly, mypy generates the same error in this case.)
You haven't provided a type annotation for the
self
parameter in thebark
method, so its type is implicitlytyping.Self
. If your intent is for it to beJee
, you can annotate it as such, but that means this method won't be callable for certain specializations ofBar
. If you wantbark
to work with all parameterizations ofBar
, then you'd need to change the return type ofbark
toSelf
.