pylance-release
pylance-release copied to clipboard
Add "implement all inherited abstract classes" code action as a quick fix for reportAbstractUsage
I was trying out the "implement all inherited abstract classes" code action which I love, and then it occurred to be that it could be nice if there was also a quick fix available when reportAbstractUsage
is reported due to the class being instantiated without having the abstract methods implemented (when typecheckingmode
is set to basic
or strict
). For example:
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
@abstractmethod
def perimeter(self):
pass
class Rectangle(Shape):
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length*self.width
### missing perimeter here
rectangle = Rectangle(5, 3) ### --> reportAbstractUsage reported due to missing perimeter implementation under Rectangle
I guess there may be problem of differentiating this error vs when it happens due to someone calling e.g. shape = Shape()
, since it also reports the same error?
cc @StellaHuang95
This issue has been fixed in prerelease version 2024.5.100, which we've just released. You can find the changelog here: CHANGELOG.md