Skip to content

Commit 9f279e4

Browse files
committed
coalib/abstractions: Add LinterClass.py
Introduce a virtual base class for linters and use it to improve the check inside `LocalBearTestHelper`. i.e. Instead of checking `hasattr(cls, 'process_output')`, an `isinstance(cls, LinterClass)` is safer and easier to understand. Related to #4594
1 parent 0415ef1 commit 9f279e4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: coalib/bearlib/abstractions/Linter.py

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from subprocess import check_call, CalledProcessError, DEVNULL
99
from types import MappingProxyType
1010

11+
from coalib.bearlib.abstractions.LinterClass import LinterClass
1112
from coalib.bears.LocalBear import LocalBear
1213
from coalib.bears.GlobalBear import GlobalBear
1314
from coala_utils.ContextManagers import make_temp
@@ -737,6 +738,7 @@ def create_arguments(config_file):
737738
result_klass = type(klass.__name__, (klass, LinterBaseClass), {
738739
'__module__': klass.__module__})
739740
result_klass.__doc__ = klass.__doc__ or ''
741+
LinterClass.register(result_klass)
740742
return result_klass
741743

742744

@@ -835,6 +837,11 @@ def linter(executable: str,
835837
and ``use_stderr=False`` raises a ``ValueError``. By default ``use_stdout``
836838
is ``True`` and ``use_stderr`` is ``False``.
837839
840+
Every ``linter`` is also a subclass of the ``LinterClass`` class.
841+
842+
>>> issubclass(XLintBear, LinterClass)
843+
True
844+
838845
Documentation:
839846
Bear description shall be provided at class level.
840847
If you document your additional parameters inside ``create_arguments``,

Diff for: coalib/bearlib/abstractions/LinterClass.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from abc import ABCMeta
2+
3+
4+
class LinterClass(metaclass=ABCMeta):
5+
"""
6+
Every ``linter`` is also a subclass of the ``LinterClass`` class.
7+
"""

0 commit comments

Comments
 (0)