mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-13 14:36:58 +07:00
Report error for abstract method in non-abstract class. GitOrigin-RevId: 824d45a310b95ada628d6e607ae1ced6e351d849
57 lines
1.1 KiB
HTML
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> |