Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coalib/abstractions: Add LinterClass.py #4595

Merged
merged 2 commits into from Aug 2, 2017
Merged

Conversation

@yash-nisar
Copy link
Member

@yash-nisar yash-nisar commented Jul 30, 2017

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.

Closes #4594

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

@yash-nisar
Copy link
Member Author

@yash-nisar yash-nisar commented Jul 30, 2017

@Makman2 Cleaning up is left, but how does the overall PR look ?

@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch Jul 30, 2017
coalib/bearlib/abstractions/Linter.py Outdated
@@ -711,6 +714,8 @@ class GlobalLinterMeta(type(LinterBase), type(GlobalBear)):

class GlobalLinterBase(LinterBase, GlobalBear, metaclass=GlobalLinterMeta):

LinterParent.register(LinterBase)

This comment has been minimized.

@Makman2

Makman2 Jul 30, 2017
Member

Could we just call it Linter? That reads just nicer:

if isinstance(..., Linter):

This comment has been minimized.

@yash-nisar

yash-nisar Jul 31, 2017
Author Member

There would be a filename conflict because we already have a file called Linter.py and shouldn't the class name be the same as the filename ?

This comment has been minimized.

@Makman2

Makman2 Jul 31, 2017
Member

hm... maybe put it into Linter.py then? Hopefully nobody needs to import like this then...

from coalib.abstractions.Linter import linter, Linter

This comment has been minimized.

@Makman2

Makman2 Jul 31, 2017
Member

or maybe call it LinterClass or so... LinterParent sounds just not right^^

This comment has been minimized.

@yash-nisar

yash-nisar Jul 31, 2017
Author Member

I vote for LinterClass 👍

coalib/bearlib/abstractions/Linter.py Outdated
@@ -711,6 +714,8 @@ class GlobalLinterMeta(type(LinterBase), type(GlobalBear)):

class GlobalLinterBase(LinterBase, GlobalBear, metaclass=GlobalLinterMeta):

LinterParent.register(LinterBase)

This comment has been minimized.

@Makman2

Makman2 Jul 30, 2017
Member

Please document that too :)

coalib/bearlib/abstractions/Linter.py Outdated
@@ -711,6 +714,8 @@ class GlobalLinterMeta(type(LinterBase), type(GlobalBear)):

class GlobalLinterBase(LinterBase, GlobalBear, metaclass=GlobalLinterMeta):

LinterParent.register(LinterBase)

This comment has been minimized.

@Makman2

Makman2 Jul 30, 2017
Member

Why not putting this into LinterBase? it seems that every class will inherit it

This comment has been minimized.

@yash-nisar

yash-nisar Jul 31, 2017
Author Member

Done 👍

coalib/testing/LocalBearTestHelper.py Outdated
@@ -20,7 +21,7 @@ def execute_bear(bear, *args, **kwargs):
# For linters provide additional information, such as
# stdout and stderr.
with ExitStack() as stack:
if hasattr(bear, 'process_output'):
if isinstance(bear, LinterParent):

This comment has been minimized.

@Makman2

Makman2 Jul 30, 2017
Member

separate commit for using it actually 👍

@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch Jul 31, 2017
@yash-nisar
Copy link
Member Author

@yash-nisar yash-nisar commented Jul 31, 2017

Updated @Makman2

coalib/bearlib/abstractions/Linter.py Outdated
@@ -677,6 +682,8 @@ def __repr__(self):
return '<{} linter object (wrapping {!r}) at {}>'.format(
type(self).__name__, self.get_executable(), hex(id(self)))

LinterParent.register(LinterBase)

This comment has been minimized.

@Makman2

Makman2 Jul 31, 2017
Member

actually doing this would register LinterBase again and again.

We should register result_klass before returning imo. Or we could just do

class LinterBase(LinterClass, metaclass=LinterMeta):

though not sure what's better^^

This comment has been minimized.

@yash-nisar

yash-nisar Jul 31, 2017
Author Member

This results in a metaclass conflict, tried that as my first resort.

coalib/bearlib/abstractions/Linter.py Outdated
"""
The ``LinterBase`` class is also a subclass of the ``LinterParent``
class.
"""

This comment has been minimized.

@Makman2

Makman2 Jul 31, 2017
Member

Document that inside the @linter documentation, not here :) LinterBase is not exposed outside.

coalib/bearlib/abstractions/LinterParent.py Outdated
from abc import ABCMeta


class LinterParent(metaclass=ABCMeta):

This comment has been minimized.

@Makman2

Makman2 Jul 31, 2017
Member

I want tests for this feature ;)

This comment has been minimized.

@yash-nisar

yash-nisar Jul 31, 2017
Author Member

Will doctests do ?

@Makman2
Copy link
Member

@Makman2 Makman2 commented Jul 31, 2017

Not sure about the commit message:

Replace `hasattr(cls, 'process_output')`

imo it should resemble this part of information you've described in the body:

an isinstance(cls, LinterParent) is safer and easier to understand

@Makman2
Copy link
Member

@Makman2 Makman2 commented Jul 31, 2017

Both issues close the same issue, that's technically not possible. If both are a part of the issue, write inside the PR message that it closes the issue, and inside the commits refer to the issue with Related to ...

@yash-nisar yash-nisar changed the title coalib/abstractions: Add LinterParent.py coalib/abstractions: Add LinterClass.py Jul 31, 2017
@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch 3 times, most recently Jul 31, 2017
@yash-nisar
Copy link
Member Author

@yash-nisar yash-nisar commented Aug 1, 2017

Updated @Makman2

coalib/bearlib/abstractions/Linter.py Outdated
@@ -766,6 +768,11 @@ def linter(executable: str,
... def create_arguments(filename, file, config_file):
... return "--lint", filename

The ``LinterBase`` class is also a subclass of the ``LinterClass`` class.

This comment has been minimized.

@Makman2

Makman2 Aug 1, 2017
Member

Rephrase to omit LinterBase!

@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch Aug 2, 2017
coalib/bearlib/abstractions/LinterClass.py Outdated
An abstract base class for linter bears that registers the ``LinterBase``
class.
"""
pass

This comment has been minimized.

@gitmate-bot

gitmate-bot Aug 2, 2017
Collaborator

This file contains unused source code.

Origin: PyUnusedCodeBear, Section: flakes.

The issue can be fixed by applying the following patch:

--- a/coalib/bearlib/abstractions/LinterClass.py
+++ b/coalib/bearlib/abstractions/LinterClass.py
@@ -6,4 +6,3 @@
     An abstract base class for linter bears that registers the ``LinterBase``
     class.
     """
-    pass
@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch Aug 2, 2017
@yash-nisar
Copy link
Member Author

@yash-nisar yash-nisar commented Aug 2, 2017

Updated @Makman2

coalib/bearlib/abstractions/LinterClass.py Outdated
class LinterClass(metaclass=ABCMeta):
"""
An abstract base class for linter bears that registers the ``LinterBase``
class.

This comment has been minimized.

@Makman2

Makman2 Aug 2, 2017
Member

the docstring is wrong ;)

This comment has been minimized.

@yash-nisar

yash-nisar Aug 2, 2017
Author Member

Fixed 👍

coalib/bearlib/abstractions/Linter.py Outdated

>>> issubclass(XLintBear, LinterClass)
True

This comment has been minimized.

@Makman2

Makman2 Aug 2, 2017
Member

I would maybe put the documentation before the Documentation: ... part. Imo it doesn't fit here very well^^

This comment has been minimized.

@yash-nisar

yash-nisar Aug 2, 2017
Author Member

Fixed 👍

coalib/bearlib/abstractions/Linter.py Outdated
@@ -766,6 +768,11 @@ def linter(executable: str,
... def create_arguments(filename, file, config_file):
... return "--lint", filename

The class is also a subclass of the ``LinterClass`` class.

This comment has been minimized.

@Makman2

Makman2 Aug 2, 2017
Member

-->
Every linter is also a subclass of the LinterClass class.

This comment has been minimized.

@yash-nisar

yash-nisar Aug 2, 2017
Author Member

Done 👍

@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch Aug 2, 2017
@Makman2
Copy link
Member

@Makman2 Makman2 commented Aug 2, 2017

ack f52a849 284635c

yash-nisar added 2 commits Jul 30, 2017
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
Replace `hasattr(cls, 'process_output')` by
`isinstance(cls, LinterClass)` in `LocalBearTestHelper`.
Instead of checking `hasattr(cls, 'process_output')`, an
`isinstance(cls, LinterClass)` is safer and easier to understand.

Related to #4594
@yash-nisar yash-nisar force-pushed the yash-nisar:virtual-class branch to 2816dc6 Aug 2, 2017
@yash-nisar
Copy link
Member Author

@yash-nisar yash-nisar commented Aug 2, 2017

@Makman2
Copy link
Member

@Makman2 Makman2 commented Aug 2, 2017

@rultor merge

@rultor
Copy link
Contributor

@rultor rultor commented Aug 2, 2017

@rultor merge

@Makman2 OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 2816dc6 into coala:master Aug 2, 2017
6 of 9 checks passed
6 of 9 checks passed
ci/circleci CircleCI is running your tests
Details
continuous-integration/appveyor/branch Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
codecov/project 100% (target 100%)
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
review/gitmate/commit This commit has no issues. :)
Details
review/gitmate/manual This commit was acknowledged.
Details
review/gitmate/pr This PR has no issues. :)
Details
@rultor
Copy link
Contributor

@rultor rultor commented Aug 2, 2017

@rultor merge

@Makman2 Done! FYI, the full log is here (took me 2min)

@yash-nisar yash-nisar deleted the yash-nisar:virtual-class branch Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.