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

Move message adding functions from MessagesHandlerMixIn #5129

Merged
merged 1 commit into from
Oct 10, 2021

Conversation

DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Oct 7, 2021

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Write a good description on what the PR does.

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

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 πŸ˜…

@@ -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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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 #?

Copy link
Member

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(
Copy link
Collaborator Author

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].

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas Oct 9, 2021

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 ?

Copy link
Collaborator Author

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.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas Oct 10, 2021

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.

Copy link
Collaborator Author

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:
Copy link
Collaborator Author

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(
Copy link
Collaborator Author

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))
Copy link
Collaborator Author

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")
Copy link
Collaborator Author

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.

@coveralls
Copy link

coveralls commented Oct 7, 2021

Pull Request Test Coverage Report for Build 1317624768

  • 90 of 91 (98.9%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage remained the same at 93.199%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pylint/lint/pylinter.py 87 88 98.86%
Files with Coverage Reduction New Missed Lines %
pylint/message/message_handler_mix_in.py 1 93.59%
Totals Coverage Status
Change from base Build 1317385477: 0.0%
Covered Lines: 13539
Relevant Lines: 14527

πŸ’› - Coveralls

@Pierre-Sassoulas Pierre-Sassoulas added the Maintenance Discussion or action around maintaining pylint or the dev workflow label Oct 10, 2021
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

@DanielNoord DanielNoord merged commit 1eaf5aa into pylint-dev:main Oct 10, 2021
@DanielNoord DanielNoord deleted the move-add-message branch October 10, 2021 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining pylint or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants