Files
Petr e1b380f8b9 PY-12132 Support ABC classes (pep-3119)
Report error for abstract method in non-abstract class.

(cherry picked from commit 824d45a310b95ada628d6e607ae1ced6e351d849)

GitOrigin-RevId: 446cfea2ab76611d13648c17d6f7419fdefa0954
2025-04-23 23:27:31 +00:00

57 lines
1.1 KiB
HTML

<html>
<body>
<p>Reports invalid definition and usages of abstract classes.</p>
<p><b>Example:</b></p>
<pre><code>
from abc import abstractmethod, ABC
class Figure(ABC):
@abstractmethod
def do_figure(self):
pass
class Triangle(Figure): # Not all abstract methods are defined in 'Triangle' class
def do_triangle(self):
pass
Triangle() # Cannot instantiate abstract class 'Triangle'
</code></pre>
<p>When the quick-fix is applied, the IDE implements an abstract method for the <code>Triangle</code> class:</p>
<pre><code>
from abc import abstractmethod, ABC
class Figure(ABC):
@abstractmethod
def do_figure(self):
pass
class Triangle(Figure):
def do_figure(self):
pass
def do_triangle(self):
pass
Triangle()
</code></pre>
It also warns you if <code>abc.abstractmethod</code> is used in a class whose metaclass is not <code>abc.ABCMeta</code>:
<code><pre>
from abc import abstractmethod
class MyClass:
@abstractmethod # 'MyClass' is not abstract
def foo(self):
...
</code></pre>
</body>
</html>