basedpyright
basedpyright copied to clipboard
use the `instance`/`owner` type to report an error when a descriptor value is used in a class that it doesn't support
from __future__ import annotations
from typing import final
class Foo:
def __get__(self, instance: Bar | None, owner: type[Bar]) -> int: ...
@final
class Bar:
asdf = Foo()
@final
class Baz:
asdf = Foo() # should be an error
related: #181
hmm you do get an error on the usage, so it's not as bad:
Bar.asdf # no error
Baz.asdf # error
here's an example where you don't get an error on the usage
from typing import reveal_type
class Foo:
def __set_name__(self, owner: type[str], value: str):
reveal_type(owner()) # str in pyright, Bar at runtime
class Bar:
asdf = Foo()