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

Distinguish between genuine typos and old configuration that could be cleaned in configuration warning #6824

Merged
merged 2 commits into from
Jun 6, 2022

Conversation

Pierre-Sassoulas
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas commented Jun 3, 2022

Type of Changes

Type
βœ“ πŸ”¨ Refactoring
βœ“ πŸ“œ Docs

Description

Deleted messages that do not exists anymore in pylint now raise useless-option-value instead of bad-option-value
which permit to distinguish between genuine typoes and old configuration that could be cleaned.

Refs #6794, #6514 ... and 2 or 3 other issues opened recently. There's also question on stackoverflow about this.

For example:
https://stackoverflow.com/questions/72486567/
https://stackoverflow.com/questions/72478704/

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels Jun 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.1 milestone Jun 3, 2022
],
"https://pylint.pycqa.org/en/latest/whatsnew/1/1.4.html#what-s-new-in-pylint-1-4-3": [
DeletedMessage("R0921", "abstract-class-not-used"),
DeletedMessage("R0922", "abstract-class-little-used"),
Copy link
Member Author

Choose a reason for hiding this comment

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

This was not documented before, I had to dig a little.

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.

Well done on finding a nice fix for this. This does indeed seem like a good middle-ground.

And well done on finding those old messages.

Some earlier comments before I do a full review/

@@ -411,9 +412,14 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
try:
meth(msgid, "module", l_start)
except exceptions.UnknownMessageError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just wonder, there are more place where we catch this exception. Should we also add this special handling there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, something really elegant would be to reraise a DeletedMessageError with the justification...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or pass the linter to the Error and add the message from the error itself?

return explanation
return None

def kwargs_for_bad_option_value_add_message(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make both of these private while we haven't documented our public API specifically.

Copy link
Member Author

Choose a reason for hiding this comment

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

We're using it in PyLinter ourself so it's complicated to make them private. I'm also ok with poeple using the is_deleted_msgid_or_symbol as a public API. What about making kwargs_for_bad_option_value_add_message protected ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think private means private to the package owner. I have used underscores to denote stuff as private but then used that in other places too. As long as it is all within the same package you can't really change stuff without immediately noticing something breaks.

is_deleted_msgid_or_symbol seems like a good utility method but I just worry that down the line we might want to change stuff to it or use a completely different method of raising these messages. After the issues we had with stuff unintentionally breaking in 2.12 and 2.13 I'm just like: as long as nobody asks for it, nobody needs it and we should just keep it to ourselves to make it easier to change stuff later on.

@@ -1,3 +1,3 @@
************* Module {abspath}
{relpath}:1:0: E0012: Bad option value for --disable. Don't recognize message logging-not-lazylogging-format-interpolation. (bad-option-value)
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message locally-disabledsuppressed-message. (bad-option-value)
{relpath}:1:0: E0012: Bad option value for '--disable'. Don't recognize message 'logging-not-lazylogging-format-interpolation'. (bad-option-value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably join the messages with a comma.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Pierre-Sassoulas My bad, I meant the message that we don't recognise πŸ˜…

But the comma you added now is also a good changed imo πŸ‘

Copy link
Member Author

Choose a reason for hiding this comment

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

Ho πŸ˜„ well this is the content of the test, if it was properly joined with a comma there would not be a bad-option-value raised. It's admittedly a little too close to what happen in real life ezczeczasxaz would have the same effect.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, I was looking at another test just above it and thought they were connected. This is indeed correct.

@coveralls
Copy link

coveralls commented Jun 3, 2022

Pull Request Test Coverage Report for Build 2446419315

  • 10 of 10 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 95.531%

Totals Coverage Status
Change from base Build 2446340211: 0.001%
Covered Lines: 16331
Relevant Lines: 17095

πŸ’› - Coveralls

@github-actions

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member Author

The primer actually find something interesting in astroid, we can't use parenthesis to justify a pragma. We had a discussion about this but I think we should just fix this in 2.14.1 and do better later.

@github-actions

This comment has been minimized.

@DanielNoord
Copy link
Collaborator

The primer actually find something interesting in astroid, we can't use parenthesis to justify a pragma. We had a discussion about this but I think we should just fix this in 2.14.1 and do better later.

Should be fixed with an additional #. Other tools require this as well, so I don't think it's too big of an issue.

I believe mypy doesn't even recognise its disables if they come after an pylint disable. They want priority πŸ˜„

@github-actions

This comment has been minimized.

.pyenchant_pylint_custom_dict.txt Outdated Show resolved Hide resolved
doc/whatsnew/2/2.14/full.rst Outdated Show resolved Hide resolved
@jacobtylerwalls jacobtylerwalls changed the title Distinguish between genuine typoes and old configuration that could be cleaned in configuration warning Distinguish between genuine typos and old configuration that could be cleaned in configuration warning Jun 4, 2022
@github-actions

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas marked this pull request as draft June 5, 2022 06:53
@Pierre-Sassoulas
Copy link
Member Author

Sorry to make changes after your review @jacobtylerwalls, but I figured:

  • bad-option-value is not an "error", in the sense that it's not going to break the code, it's only a potential problem in pylint. So it make sense to make it a warning and to not be warned for this in --error-only mode (only problem could be if a user think he enabled a message and it's not enabled, but it must have been disabled previously so I think it's unlikely to happen).
  • We were adding a new message in a patch version, we need to use old_names so the previous disable still works. Otherwise people that already got bothered by 2.14.0 and disabled bad-option-value will still get useless-option-value... that can be annoying.

So I'm going to add a new commit using old-names this time.

@Pierre-Sassoulas Pierre-Sassoulas marked this pull request as ready for review June 5, 2022 07:30
@DanielNoord
Copy link
Collaborator

@Pierre-Sassoulas I'd advise against making this an I warning. I think W is better. Information warnings are turned off by default and need to be turned on individually. So nobody will likely every find this message.

@DanielNoord
Copy link
Collaborator

Sure, but isn't it exactly what we're doing now ? useless-option-value is not a new message, it's the new name of bad-option-value (with its sister message unknown-option-value) ? I agree we should not reuse number in new messages for precisely this scenario.

Yeah, one of them should keep 0012, but the other should get its own number. We don't really have a concept of "sister messages" and I don't think we should start creating those.

@Pierre-Sassoulas
Copy link
Member Author

We don't really have a concept of "sister messages"

In fact the only other messages used multiple time as old_name is missing-docstring but we did not change the message type of the children so we did C0111 => [C0012 C0013 C0014]

@DanielNoord
Copy link
Collaborator

We don't really have a concept of "sister messages"

In fact the only other messages used multiple time as old_name is missing-docstring but we did not change the message type of the children so we did C0111 => [C0012 C0013 C0014]

I was more referring to messages that are related but are on different levels. To take docstring as an example. Let's say we find module docstrings more important we could have C0012 for missing-function-docstring and E0012 for missing-module-docstring.
Coupling messages across different levels like that might only create issues down the line I think. We're changing the symbols of these messages anyway and we're not running out of IDs so I really don't see why would want to couple them like that.
It is also confusing for users as we would have C0012, R0012 and W0012 which are all different messages but with almost the same id.

@Pierre-Sassoulas
Copy link
Member Author

Sorry for rebasing but I think the commits need to be separated. I renamed R0012 to R0022 (first number not used elsewhere in main checker).

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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.

Just some initial review. If you're able to perhaps split some changes from this PR. There is a lot going on, with some of it just being general refactoring. Makes it quite hard to review this.

After all the opened issues I'd like to get this right once and for all.

doc/data/messages/b/bad-option-value/bad.py Outdated Show resolved Hide resolved
@@ -71,7 +73,6 @@ def get_functional_test_files_from_directory(input_dir: Path) -> List[Tuple[str,
class LintModuleTest:
def __init__(self, test_file: Tuple[str, Path]) -> None:
self._test_file = test_file
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably your IDE but your PRs keep removing white lines. This is just personal preferences, but I kinda like how white lines can separate different elements within a function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha no, it's personal preference, imo compactness is good for readability, I think creating smaller code unit with functions also make more sense if something need to be separated. Anyway I'm going to stop doing that if you don't like it as we don't need churn around this.

doc/test_messages_documentation.py Outdated Show resolved Hide resolved
doc/whatsnew/2/2.14/full.rst Outdated Show resolved Hide resolved
doc/whatsnew/2/2.14/full.rst Outdated Show resolved Hide resolved
@Pierre-Sassoulas
Copy link
Member Author

There is a lot going on, with some of it just being general refactoring. Makes it quite hard to review this.

Right let's start by #6866

@Pierre-Sassoulas
Copy link
Member Author

Then #6867. Even if we don't need to activate the old messages there was still some things to keep there.

@github-actions

This comment has been minimized.

So it's possible to to distinguish between genuine typoes and old
configuration that could be cleaned.

We use old_names to decrease message type to warning
Previousely they were considered unknown names.
@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2022

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on astroid:
The following messages are now emitted:

  1. unknown-option-value:
    Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'
    https://github.com/PyCQA/astroid/blob/main/astroid/__init__.py#L91
  2. unknown-option-value:
    Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'
    https://github.com/PyCQA/astroid/blob/main/astroid/node_classes.py#L9
  3. unknown-option-value:
    Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'
    https://github.com/PyCQA/astroid/blob/main/astroid/nodes/__init__.py#L15

The following messages are no longer emitted:

  1. bad-option-value:
    Bad option value for 'disable', expected a valid pylint message and got 'Ellipsis'
    https://github.com/PyCQA/astroid/blob/main/astroid/__init__.py#L91
  2. bad-option-value:
    Bad option value for 'disable', expected a valid pylint message and got 'Ellipsis'
    https://github.com/PyCQA/astroid/blob/main/astroid/node_classes.py#L9
  3. bad-option-value:
    Bad option value for 'disable', expected a valid pylint message and got 'Ellipsis'
    https://github.com/PyCQA/astroid/blob/main/astroid/nodes/__init__.py#L15

This comment was generated for commit c5f0ce1

@Pierre-Sassoulas Pierre-Sassoulas merged commit a5ca674 into main Jun 6, 2022
@Pierre-Sassoulas Pierre-Sassoulas deleted the useless-option-value branch June 6, 2022 08:38
@Pierre-Sassoulas Pierre-Sassoulas added Backported and removed Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants