-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Move message adding functions from MessagesHandlerMixIn
#5129
Conversation
753314a
to
1f080c0
Compare
1f080c0
to
38df06e
Compare
@@ -519,7 +536,11 @@ def __init__(self, options=(), reporter=None, option_groups=(), pylintrc=None): | |||
"disable-msg": self._options_methods["disable"], | |||
"enable-msg": self._options_methods["enable"], | |||
} | |||
MessagesHandlerMixIn.__init__(self) | |||
|
|||
# Attributes related to message (state) handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These come from MessagesHandlerMixIn.init()
. They could be their own PR but I thought this fitted.
@@ -1300,3 +1321,196 @@ def _report_evaluation(self): | |||
sect = report_nodes.EvaluationSection(msg) | |||
self.reporter.display_reports(sect) | |||
return note | |||
|
|||
# Adding (ignored) messages to the Message Reporter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a better way to indicate a section of functions without running into https://www.flake8rules.com/rules/E266.html
I really dislike how # IAstroidChecker interface #################################################
looks on L1248.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need separators because we have a badly designed god class with 1500+ lines, I would classify having a nicer looking separator as "polishing a turd". Granted we're probably not re-designing pylinter any time soon but... well I think this separator is good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, although I don't immediately know how to redesign PyLinter
without passing self
as a parameter to functions that are now methods. A lot of its methods require access to self
...
This separator as in the one I added right now? Or do you want me to add the additional #
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separator are good enough let's leave them all as is :)
|
||
# Adding (ignored) messages to the Message Reporter | ||
|
||
def _get_message_state_scope( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a private method. The # type: ignore
's are necessary because mypy
doesn't infer that the return values are constants and complains that the return value should be Optional[int]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we're testing this function in the tests. Generally, I would say that if a function is private you don't need to test it directly and can test it through the public function. Could it be a subclass with message related code instead (MessageHandler
?) ? Then we'd be using that class in Pylinter using composition instead of inheritance and we'd be able to test it without accessing private function (and pylinter would be more manageable).
I tried to do that at some point and there was a problem because some function are called with self being a MessageHandlerMixin
at some point and then a Pylinter
at another point. Which as you said is bad design, (but also hard to refactor). What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at this but we need self.file_state._module_msgs_state[msgid]:
at L1339 here. As well as self.config
on L1336. We could pass self
as parameter, but I think that would be part of a bigger redesign (see previous comment). For now I think removing MessagesHandlerMixIn
is a good first step.
I don't necessarily agree with the private method testing, but I also don't know what is standard for other python
projects. I feel like it is always good to test a function directly as you can diagnose potential problems directly. If we test this by testing the functions that call it and those tests fail we will need an additional step to diagnose the problem. Testing private methods directly makes it easier to diagnose regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a Python standard, it's a general standard. It means you can modify private function without changing tests or code. Ie implementation details are hidden (for example move from a polar representation to cartesian in a coordinate class without changing the interface). Or if it should be public and his hidden to simplify the class api it forces to put the code in another code unit that is tested itself, smaller and simpler. (I suppose you made the function private to simplify pylinter's api but i'd like to know your rationale if that's not it)
Anyway, seeing the complexity of pylinter, it's not the time to aim for theorical purity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood!
Is this good to go then?
return MSG_STATE_SCOPE_CONFIG # type: ignore | ||
return None | ||
|
||
def _is_one_message_enabled(self, msgid: str, line: Optional[int]) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a private method
return True | ||
return False | ||
|
||
def _add_one_message( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a private method. Note that args
remains Any
, to be tackled at a different time.
if message_line <= line | ||
] | ||
) | ||
_, fallback_iter = next(closest_lines, (None, None)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed how this works because mypy
was unable to follow what was happening here. The results remains the same.
@@ -316,14 +316,14 @@ class FakeConfig: | |||
|
|||
linter = init_linter | |||
linter.disable("C0202") | |||
assert MSG_STATE_SCOPE_CONFIG == linter.get_message_state_scope("C0202") | |||
assert MSG_STATE_SCOPE_CONFIG == linter._get_message_state_scope("C0202") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To accommodate the change to the method being private.
Pull Request Test Coverage Report for Build 1317624768
π - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π
Type of Changes
Description
Ref #5018
Almost there π
This should be second-to-last PR and includes all functions related to adding message to the reporter.
I'll review and annotate the code because there are some hard to spot changes included with this move.
Sorry for the rebase spam. Made two silly (spelling) mistakes in comments π