-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[deleted messages] Refactor the constant to be able to give a reason #6826
Merged
Pierre-Sassoulas
merged 2 commits into
pylint-dev:main
from
Pierre-Sassoulas:refactor-deleted-messages
Jun 4, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE | ||
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt | ||
|
||
from __future__ import annotations | ||
|
||
from functools import lru_cache | ||
from typing import NamedTuple | ||
|
||
|
||
class DeletedMessage(NamedTuple): | ||
msgid: str | ||
symbol: str | ||
old_names: list[tuple[str, str]] = [] | ||
|
||
|
||
DELETED_MSGID_PREFIXES: list[int] = [] | ||
|
||
DELETED_MESSAGES_IDS = { | ||
# Everything until the next comment is from the PY3K+ checker | ||
"https://github.com/PyCQA/pylint/pull/4942": [ | ||
DeletedMessage("W1601", "apply-builtin"), | ||
DeletedMessage("E1601", "print-statement"), | ||
DeletedMessage("E1602", "parameter-unpacking"), | ||
DeletedMessage( | ||
"E1603", "unpacking-in-except", [("W0712", "old-unpacking-in-except")] | ||
), | ||
DeletedMessage( | ||
"E1604", "old-raise-syntax", [("W0121", "old-old-raise-syntax")] | ||
), | ||
DeletedMessage("E1605", "backtick", [("W0333", "old-backtick")]), | ||
DeletedMessage("E1609", "import-star-module-level"), | ||
DeletedMessage("W1601", "apply-builtin"), | ||
DeletedMessage("W1602", "basestring-builtin"), | ||
DeletedMessage("W1603", "buffer-builtin"), | ||
DeletedMessage("W1604", "cmp-builtin"), | ||
DeletedMessage("W1605", "coerce-builtin"), | ||
DeletedMessage("W1606", "execfile-builtin"), | ||
DeletedMessage("W1607", "file-builtin"), | ||
DeletedMessage("W1608", "long-builtin"), | ||
DeletedMessage("W1609", "raw_input-builtin"), | ||
DeletedMessage("W1610", "reduce-builtin"), | ||
DeletedMessage("W1611", "standarderror-builtin"), | ||
DeletedMessage("W1612", "unicode-builtin"), | ||
DeletedMessage("W1613", "xrange-builtin"), | ||
DeletedMessage("W1614", "coerce-method"), | ||
DeletedMessage("W1615", "delslice-method"), | ||
DeletedMessage("W1616", "getslice-method"), | ||
DeletedMessage("W1617", "setslice-method"), | ||
DeletedMessage("W1618", "no-absolute-import"), | ||
DeletedMessage("W1619", "old-division"), | ||
DeletedMessage("W1620", "dict-iter-method"), | ||
DeletedMessage("W1621", "dict-view-method"), | ||
DeletedMessage("W1622", "next-method-called"), | ||
DeletedMessage("W1623", "metaclass-assignment"), | ||
DeletedMessage( | ||
"W1624", "indexing-exception", [("W0713", "old-indexing-exception")] | ||
), | ||
DeletedMessage("W1625", "raising-string", [("W0701", "old-raising-string")]), | ||
DeletedMessage("W1626", "reload-builtin"), | ||
DeletedMessage("W1627", "oct-method"), | ||
DeletedMessage("W1628", "hex-method"), | ||
DeletedMessage("W1629", "nonzero-method"), | ||
DeletedMessage("W1630", "cmp-method"), | ||
DeletedMessage("W1632", "input-builtin"), | ||
DeletedMessage("W1633", "round-builtin"), | ||
DeletedMessage("W1634", "intern-builtin"), | ||
DeletedMessage("W1635", "unichr-builtin"), | ||
DeletedMessage( | ||
"W1636", "map-builtin-not-iterating", [("W1631", "implicit-map-evaluation")] | ||
), | ||
DeletedMessage("W1637", "zip-builtin-not-iterating"), | ||
DeletedMessage("W1638", "range-builtin-not-iterating"), | ||
DeletedMessage("W1639", "filter-builtin-not-iterating"), | ||
DeletedMessage("W1640", "using-cmp-argument"), | ||
DeletedMessage("W1642", "div-method"), | ||
DeletedMessage("W1643", "idiv-method"), | ||
DeletedMessage("W1644", "rdiv-method"), | ||
DeletedMessage("W1645", "exception-message-attribute"), | ||
DeletedMessage("W1646", "invalid-str-codec"), | ||
DeletedMessage("W1647", "sys-max-int"), | ||
DeletedMessage("W1648", "bad-python3-import"), | ||
DeletedMessage("W1649", "deprecated-string-function"), | ||
DeletedMessage("W1650", "deprecated-str-translate-call"), | ||
DeletedMessage("W1651", "deprecated-itertools-function"), | ||
DeletedMessage("W1652", "deprecated-types-field"), | ||
DeletedMessage("W1653", "next-method-defined"), | ||
DeletedMessage("W1654", "dict-items-not-iterating"), | ||
DeletedMessage("W1655", "dict-keys-not-iterating"), | ||
DeletedMessage("W1656", "dict-values-not-iterating"), | ||
DeletedMessage("W1657", "deprecated-operator-function"), | ||
DeletedMessage("W1658", "deprecated-urllib-function"), | ||
DeletedMessage("W1659", "xreadlines-attribute"), | ||
DeletedMessage("W1660", "deprecated-sys-function"), | ||
DeletedMessage("W1661", "exception-escape"), | ||
DeletedMessage("W1662", "comprehension-escape"), | ||
], | ||
"https://github.com/PyCQA/pylint/pull/3578": [ | ||
DeletedMessage("W0312", "mixed-indentation"), | ||
], | ||
"https://github.com/PyCQA/pylint/pull/3577": [ | ||
DeletedMessage( | ||
"C0326", | ||
"bad-whitespace", | ||
[ | ||
("C0323", "no-space-after-operator"), | ||
("C0324", "no-space-after-comma"), | ||
("C0322", "no-space-before-operator"), | ||
], | ||
), | ||
], | ||
"https://github.com/PyCQA/pylint/pull/3571": [ | ||
DeletedMessage("C0330", "bad-continuation") | ||
], | ||
"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"), | ||
DeletedMessage("W0142", "star-args"), | ||
], | ||
"https://github.com/PyCQA/pylint/issues/2409": [ | ||
DeletedMessage("W0232", "no-init"), | ||
], | ||
"https://github.com/PyCQA/pylint/pull/6421": [ | ||
DeletedMessage("W0111", "assign-to-new-keyword"), | ||
], | ||
} | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def is_deleted_symbol(symbol: str) -> str | None: | ||
"""Return the explanation for removal if the message was removed.""" | ||
for explanation, deleted_messages in DELETED_MESSAGES_IDS.items(): | ||
for deleted_message in deleted_messages: | ||
if symbol == deleted_message.symbol: | ||
return explanation | ||
return None | ||
|
||
|
||
@lru_cache(maxsize=None) | ||
def is_deleted_msgid(msgid: str) -> str | None: | ||
"""Return the explanation for removal if the message was removed.""" | ||
for explanation, deleted_messages in DELETED_MESSAGES_IDS.items(): | ||
for deleted_message in deleted_messages: | ||
if msgid == deleted_message.msgid: | ||
return explanation | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/config/functional/ini/pylintrc_with_deleted_message.2.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
************* Module {abspath} | ||
{relpath}:1:0: E0012: Bad option value for --disable. Don't recognize message buffer-builtin. (bad-option-value) | ||
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message useless-option-value. (bad-option-value) | ||
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message cmp-builtin. (bad-option-value) |
7 changes: 7 additions & 0 deletions
7
tests/config/functional/ini/pylintrc_with_deleted_message.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Check that we raise an informational when a deleted messages exists in a .pylintrc file | ||
# See https://github.com/PyCQA/pylint/issues/6794 | ||
[messages control] | ||
disable = logging-not-lazy, buffer-builtin | ||
enable = useless-option-value, locally-disabled, cmp-builtin | ||
jobs = 10 | ||
reports = yes |
12 changes: 12 additions & 0 deletions
12
tests/config/functional/ini/pylintrc_with_deleted_message.result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"functional_append": { | ||
"disable": ["logging-not-lazy"], | ||
"enable": ["locally-disabled"] | ||
}, | ||
"functional_remove": { | ||
"disable": ["locally-disabled"], | ||
"enable": ["logging-not-lazy"] | ||
}, | ||
"jobs": 10, | ||
"reports": true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sorry about the unrelated change but I don't know why suddenly pre-commit pylint was not happy about this.
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 must have a dictionary with both mimic and mimick.
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 might want to add to our own dictionary instead of disabling because the
useless-suppression
it will get annoying fast.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 because you removed a
disable
on L206.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.
No, I had the useless suppression, thougth it was a spellcheck issue, "fixed" "mimick" (suggestion from IDE) then still had an useless-suppression, and removed the disable. I think it's the dict that has "mimick" in it on ubuntu.
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.
Let's add
useless-suppression
to the disable there then. Because the other stuff in that comment still needs to be disabled.