Files
openide/python/python-psi-impl/resources/inspectionDescriptions/PyAbstractClassInspection.html
Petr 3060358b39 PY-12132 Support ABC classes (pep-3119)
Report error for abstract method in non-abstract class.

GitOrigin-RevId: 824d45a310b95ada628d6e607ae1ced6e351d849
2025-04-09 14:53:21 +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>