basedpyright
basedpyright copied to clipboard
inlay hint for split def attribute only includes the initial part of the definition
Description
class A:
a`: int` = 1
def f(self):
self.a = "a"
i would expect : int | str
context for anyone wondering why there's no error when assigning a str to self.a, it's because a's type is actually inferred as int | str but it displays the wrong inlay hint.
Code sample in basedpyright playground
from typing import reveal_type
class A:
a = 1
def f(self):
self.a = "a"
reveal_type(A().a) # int | str
interestingly, the same can't be said about ClassVars
Code sample in basedpyright playground
from typing import ClassVar, reveal_type
class A:
a: ClassVar = 1
@classmethod
def f(cls):
cls.a = "a"
A.f()
reveal_type(A().a) # basedpyright: int, runtime: str
#1542