-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Rename check_messages
#6196
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
Rename check_messages
#6196
Conversation
…kwards compatibility.
DanielNoord
left a comment
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.
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?
Pull Request Test Coverage Report for Build 2176347274
💛 - Coveralls |
|
|
Co-authored-by: Daniël van Noord <[email protected]>
+1 for |
Pierre-Sassoulas
left a comment
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.
Looks great. Should we also migrate everything in this MR ?
pylint/checkers/utils.py
Outdated
| 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 |
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 think we can activate it right now so we see if we migrated everything by seeing the warnings in tests :)
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.
If this does not lead to a failed CI pipeline, we can activate it right away. 👍
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 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.
|
If we want to just rename all occurrences of |
pylint/checkers/utils.py
Outdated
| *messages: str, | ||
| ) -> Callable[ | ||
| [Callable[[Any, nodes.NodeNG], None]], Callable[[Any, nodes.NodeNG], 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.
@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.
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.
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)
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.
Thanks, that worked!
|
@Pierre-Sassoulas let me know if you want me to do the renaming directly in this PR. :) |
Pierre-Sassoulas
left a comment
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.
LGTM, let's separate the deprecation and the migration as you said it's clearer.
| import astroid | ||
|
|
||
| from pylint.checkers.utils import check_messages | ||
| from pylint.checkers.utils import only_required_for_messages |
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.
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.
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.
Yes, that makes sense - will do!
Co-authored-by: Daniël van Noord <[email protected]>
|
@DanielNoord any idea why the tests are failing on Python 3.8 and below? |
|
|
||
| T_Node = TypeVar("T_Node", bound=nodes.NodeNG) | ||
| CheckerT = TypeVar("CheckerT", bound=BaseChecker) | ||
| AstCallback = Callable[[CheckerT, T_Node], 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.
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).
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 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.
for more information, see https://pre-commit.ci
|
I checked locally and importing from |
See pylint-dev/pylint#6196 Change-Id: I28ef1b0ea9911451699aeee7f78be4949bde1224
and preferred name in
script/.contributors_aliases.jsonType of Changes
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
DeprecationWarningyet before we have not removed/renamed all usages ourselves.I chose to not include it in the official documentation, as
@check_messageswas 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