ruff
fb2b844c - [ty] Consider synthesized methods and `ClassVar`-qualified declarations when determining whether an abstract method has been overridden in a subclass (#23381)

Commit
1 day ago
[ty] Consider synthesized methods and `ClassVar`-qualified declarations when determining whether an abstract method has been overridden in a subclass (#23381) ## Summary This is another standalone PR pulled out of #22898, to reduce the diff on that PR. Currently we emit a false-positive `abstract-method-in-final-class` diagnostic on this class, because we do not see that the synthesized `__lt__` method created by `@dataclass(order=True)` has overridden the abstract `__lt__` method from the class's superclass: ```py from abc import ABC, abstractmethod from dataclasses import dataclass from typing import final class AbstractOrdered(ABC): @abstractmethod def __lt__(self, other): ... @final @dataclass(order=True) class ConcreteOrdered(AbstractOrdered): ... ``` We also currently do not recognise `ClassVar` declarations in a subclass as overriding an abstract method/property on a base class. While an annotation without a binding is not sufficient at runtime as an abstract method override, the `ClassVar` qualifier serves as an explicit declaration from the user to the type checker that the attribute will be accessible on the class object itself (not simply instances of the class) at runtime. We therefore choose to treat `ClassVar` declarations as overrides of abstract methods from superclasses. ## Test Plan mdtests updated/extended
Author
Parents
Loading