pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Add "implement all inherited abstract classes" code action as a quick fix for reportAbstractUsage

Open luabud opened this issue 10 months ago • 1 comments

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?

luabud avatar Apr 12 '24 19:04 luabud

cc @StellaHuang95

luabud avatar Apr 12 '24 19:04 luabud

This issue has been fixed in prerelease version 2024.5.100, which we've just released. You can find the changelog here: CHANGELOG.md

KacieKK avatar May 09 '24 23:05 KacieKK