-
|
I don't even know how to explain this in a non-confusing manner. Here is the reproduction code: import typing
type Fn[A, B] = typing.Callable[[A], B]
class __Forall[A]:
id: Fn[A, A] = lambda x: x
_A = typing.TypeVar("_A")
id_ = __Forall[_A].id
typing.reveal_type(id_) # Type of "id_" is "(__Forall[_A@id_]) -> __Forall[_A@id_]"Why is I'm not sure whether this is an actual Pyright issue, a typing spec hole, a misunderstanding of mine or something else entirely, hence I'm opening a discussion instead. Either way, I still think the current behavior is incorrect, at least in terms of accepting the definition of "implicit" Worth noting, mypy's output is the following: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
This might give you some information: #7089 |
Beta Was this translation helpful? Give feedback.
Please refer to this documentation for an explanation of how pyright treats class and instance variables. In your example, the class-scoped variable
idis treated as a "regular class variable" that may be accessed from the class but may also be overwritten by an instance. It is neither a "pure class variable" or a "pure instance variable".The typing spec does not currently provide much guidance for type checkers in this regard. It's an area where additional formalization and specification is needed.