Skip to content

Conversation

@DudeNr33
Copy link
Collaborator

@DudeNr33 DudeNr33 commented Apr 5, 2022

  • Write a good description on what the PR does.
  • If you used multiple emails or multiple names when contributing, add your mails
    and preferred name in script/.contributors_aliases.json

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

First step for cleaning up @check_messages.
Rename the decorator and improve the docstring.
Add alias for backwards compatibility, but do not emit a DeprecationWarning yet before we have not removed/renamed all usages ourselves.

I chose to not include it in the official documentation, as @check_messages was not mentioned as well. I think that most custom checkers would be very focused and would not benefit much from the decorator anyway.

Closes #6060

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Since this is mostly for internal use and we don't really need to worry about how pretty the function name is, what about checker_only_required_for? Or is that overkill?

@coveralls
Copy link

coveralls commented Apr 5, 2022

Pull Request Test Coverage Report for Build 2176347274

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • 68 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.005%) to 95.043%

Files with Coverage Reduction New Missed Lines %
pylint/testutils/functional/test_file.py 2 96.49%
pylint/checkers/refactoring/refactoring_checker.py 11 98.26%
pylint/checkers/classes/class_checker.py 18 94.25%
pylint/checkers/variables.py 18 96.64%
pylint/testutils/lint_module_test.py 19 86.44%
Totals Coverage Status
Change from base Build 2174016644: 0.005%
Covered Lines: 15685
Relevant Lines: 16503

💛 - Coveralls

@DudeNr33
Copy link
Collaborator Author

DudeNr33 commented Apr 5, 2022

checker_only_required_for sounds to me as if this decorator is meant to be applied to the checker class. Maybe only_checks_messages or only_required_for_messages?

Co-authored-by: Daniël van Noord <[email protected]>
@DanielNoord
Copy link
Collaborator

checker_only_required_for sounds to me as if this decorator is meant to be applied to the checker class. Maybe only_checks_messages or only_required_for_messages?

+1 for only_required_for_messages

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.

Looks great. Should we also migrate everything in this MR ?

Use only_required_for instead, which conveys the intent of the decorator much clearer.
"""
# Uncomment the following warning once all 'check_messages' calls have been replaced
Copy link
Member

Choose a reason for hiding this comment

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

I think we can activate it right now so we see if we migrated everything by seeing the warnings in tests :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If this does not lead to a failed CI pipeline, we can activate it right away. 👍

Copy link
Member

Choose a reason for hiding this comment

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

I think for some deprecation warnings it's hard to deactivate them (or would take too much time to catch them everywhere), so warning do not make the CI fail.

@Pierre-Sassoulas Pierre-Sassoulas added Documentation 📗 Maintenance Discussion or action around maintaining pylint or the dev workflow labels Apr 5, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.0 milestone Apr 5, 2022
@DudeNr33
Copy link
Collaborator Author

DudeNr33 commented Apr 5, 2022

If we want to just rename all occurrences of check_messages in the first step we can do that here.
If we want to combine it with actually checking if the decorator is applied correctly, I would do it checker per checker, as it would be impossible to properly review it in a single PR.

*messages: str,
) -> Callable[
[Callable[[Any, nodes.NodeNG], None]], Callable[[Any, nodes.NodeNG], 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.

@DanielNoord the typing gets really longish here. Are we sure that we want to keep it?

Also, I initially tried to put BaseChecker as first argument instead of Any, but even though I think this should be correct mypy failed, because we don't have BaseChecker instances but instances of subclasses.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to do something like this:

from typing import TypeVar
C = TypeVar('C', bound=BaseChecker)
    [Callable[[C, nodes.NodeNG], None]], Callable[[C, nodes.NodeNG], None]

Based on https://mypy.readthedocs.io/en/stable/generics.html (The Friend / SuperFriend example)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, that worked!

@DudeNr33
Copy link
Collaborator Author

DudeNr33 commented Apr 9, 2022

@Pierre-Sassoulas let me know if you want me to do the renaming directly in this PR. :)

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.

LGTM, let's separate the deprecation and the migration as you said it's clearer.

@DudeNr33 DudeNr33 requested a review from DanielNoord April 10, 2022 10:56
import astroid

from pylint.checkers.utils import check_messages
from pylint.checkers.utils import only_required_for_messages
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we add one test with pytest.warns(DeprecationWarning)? That means that coverage will remain 100% for the check_messages function and tests the deprecation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that makes sense - will do!

@DudeNr33
Copy link
Collaborator Author

@DanielNoord any idea why the tests are failing on Python 3.8 and below?

ImportError while loading conftest '/home/runner/work/pylint/pylint/tests/conftest.py'.
tests/conftest.py:[11](https://github.com/PyCQA/pylint/runs/6037209987?check_suite_focus=true#step:7:11): in <module>
    from pylint import checkers
pylint/checkers/__init__.py:49: in <module>
    from pylint.checkers.deprecated import DeprecatedMixin
pylint/checkers/deprecated.py:[16](https://github.com/PyCQA/pylint/runs/6037209987?check_suite_focus=true#step:7:16): in <module>
    from pylint.checkers import utils
pylint/checkers/utils.py:228: in <module>
    AstCallback = Callable[[CheckerT, T_Node], None]
E   TypeError: 'ABCMeta' object is not subscriptable


T_Node = TypeVar("T_Node", bound=nodes.NodeNG)
CheckerT = TypeVar("CheckerT", bound=BaseChecker)
AstCallback = Callable[[CheckerT, T_Node], None]
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll need to import Callable from typing I think. Whenever it is used in runtime it needs to be from typing (until 3.9).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is already imported from typing.
I could solve it locally with putting it inside a if TYPE_CHECKING block. Let's see if the CI is happy with that.

@DudeNr33 DudeNr33 requested a review from DanielNoord April 16, 2022 09:09
@DanielNoord
Copy link
Collaborator

I checked locally and importing from typing did work on 3.7. Sorry for pushing to your branch but I'd like to see if we can do this without the import guard.

@Pierre-Sassoulas Pierre-Sassoulas merged commit 0bd2e5a into pylint-dev:main Apr 16, 2022
@Pierre-Sassoulas Pierre-Sassoulas removed this from the 2.14.0 milestone May 17, 2022
CheckmkCI pushed a commit to Checkmk/checkmk that referenced this pull request Oct 11, 2023
See pylint-dev/pylint#6196

Change-Id: I28ef1b0ea9911451699aeee7f78be4949bde1224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation 📗 Maintenance Discussion or action around maintaining pylint or the dev workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use, misuse and confusion of @check_messages decorator

4 participants