Skip to content

Commit

Permalink
coalib/abstractions: Add LinterClass.py
Browse files Browse the repository at this point in the history
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 coala#4594
  • Loading branch information
yash-nisar committed Aug 2, 2017
1 parent 0415ef1 commit 9f279e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions coalib/bearlib/abstractions/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from subprocess import check_call, CalledProcessError, DEVNULL
from types import MappingProxyType

from coalib.bearlib.abstractions.LinterClass import LinterClass
from coalib.bears.LocalBear import LocalBear
from coalib.bears.GlobalBear import GlobalBear
from coala_utils.ContextManagers import make_temp
Expand Down Expand Up @@ -737,6 +738,7 @@ def create_arguments(config_file):
result_klass = type(klass.__name__, (klass, LinterBaseClass), {
'__module__': klass.__module__})
result_klass.__doc__ = klass.__doc__ or ''
LinterClass.register(result_klass)
return result_klass


Expand Down Expand Up @@ -835,6 +837,11 @@ def linter(executable: str,
and ``use_stderr=False`` raises a ``ValueError``. By default ``use_stdout``
is ``True`` and ``use_stderr`` is ``False``.
Every ``linter`` is also a subclass of the ``LinterClass`` class.
>>> issubclass(XLintBear, LinterClass)
True
Documentation:
Bear description shall be provided at class level.
If you document your additional parameters inside ``create_arguments``,
Expand Down
7 changes: 7 additions & 0 deletions coalib/bearlib/abstractions/LinterClass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from abc import ABCMeta


class LinterClass(metaclass=ABCMeta):
"""
Every ``linter`` is also a subclass of the ``LinterClass`` class.
"""

0 comments on commit 9f279e4

Please sign in to comment.