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

[deleted messages] Refactor the constant to be able to give a reason #6826

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pylint/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,8 @@ def _enable_all_extensions(run: Run, value: str | None) -> None:
PREPROCESSABLE_OPTIONS: dict[
str, tuple[bool, Callable[[Run, str | None], None], int]
] = { # pylint: disable=consider-using-namedtuple-or-dataclass
# pylint: disable=wrong-spelling-in-comment
# Argparse by default allows abbreviations. It behaves differently
# if you turn this off, so we also turn it on. We mimick this
# if you turn this off, so we also turn it on. We mimic this
Copy link
Member Author

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.

Copy link
Member Author

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.

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 might want to add to our own dictionary instead of disabling because the useless-suppression it will get annoying fast.

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 because you removed a disable on L206.

Copy link
Member Author

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.

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 add useless-suppression to the disable there then. Because the other stuff in that comment still needs to be disabled.

# by allowing some abbreviations or incorrect spelling here.
# The integer at the end of the tuple indicates how many letters
# should match, include the '-'. 0 indicates a full match.
Expand Down
113 changes: 0 additions & 113 deletions pylint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import platform
import sys
from datetime import datetime
from typing import NamedTuple

import astroid
import platformdirs
Expand Down Expand Up @@ -82,118 +81,6 @@ class WarningScope:
"typevar": "type variable",
}


class DeletedMessage(NamedTuple):
msgid: str
symbol: str
old_names: list[tuple[str, str]] = []


DELETED_MSGID_PREFIXES: list[int] = []

DELETED_MESSAGES = [
# Everything until the next comment is from the
# PY3K+ checker, see 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"),
# No PR
DeletedMessage("R0921", "abstract-class-not-used"),
# https://github.com/PyCQA/pylint/pull/3577
DeletedMessage("C0326", "bad-whitespace"),
# Pylint 1.4.3
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"),
]


# ignore some messages when emitting useless-suppression:
# - cyclic-import: can show false positives due to incomplete context
# - deprecated-{module, argument, class, method, decorator}:
Expand Down
11 changes: 11 additions & 0 deletions pylint/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ class UnknownMessageError(Exception):
"""Raised when an unregistered message id is encountered."""


class DeletedMessageError(UnknownMessageError):
"""Raised when a message id or symbol that was deleted from pylint is
encountered.
"""

def __init__(self, msgid_or_symbol: str, removal_explanation: str):
super().__init__(
f"'{msgid_or_symbol}' was removed from pylint, see {removal_explanation}."
)


class EmptyReportError(Exception):
"""Raised when a report is empty and so should not be displayed."""

Expand Down
146 changes: 146 additions & 0 deletions pylint/message/_deleted_message_ids.py
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
17 changes: 14 additions & 3 deletions pylint/message/message_id_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

from typing import NoReturn

from pylint.exceptions import InvalidMessageError, UnknownMessageError
from pylint.exceptions import (
DeletedMessageError,
InvalidMessageError,
UnknownMessageError,
)
from pylint.message._deleted_message_ids import is_deleted_msgid, is_deleted_symbol


class MessageIdStore:
Expand Down Expand Up @@ -122,18 +127,24 @@ def get_active_msgids(self, msgid_or_symbol: str) -> list[str]:

# If we don't have a cached value yet we compute it
msgid: str | None
deletion_reason = None
if msgid_or_symbol[1:].isdigit():
# Only msgid can have a digit as second letter
msgid = msgid_or_symbol.upper()
symbol = self.__msgid_to_symbol.get(msgid)
if not symbol:
deletion_reason = is_deleted_msgid(msgid)
else:
msgid = self.__symbol_to_msgid.get(msgid_or_symbol)
symbol = msgid_or_symbol
msgid = self.__symbol_to_msgid.get(msgid_or_symbol)
if not msgid:
deletion_reason = is_deleted_symbol(symbol)
if not msgid or not symbol:
if deletion_reason is not None:
raise DeletedMessageError(msgid_or_symbol, deletion_reason)
error_msg = f"No such message id or symbol '{msgid_or_symbol}'."
raise UnknownMessageError(error_msg)
ids = self.__old_names.get(msgid, [msgid])

# Add to cache
self.__active_msgids[msgid_or_symbol] = ids
return ids
2 changes: 1 addition & 1 deletion script/get_unused_message_id_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from __future__ import annotations

from pylint.checkers import initialize as initialize_checkers
from pylint.constants import DELETED_MSGID_PREFIXES
from pylint.extensions import initialize as initialize_extensions
from pylint.lint.pylinter import PyLinter
from pylint.message._deleted_message_ids import DELETED_MSGID_PREFIXES


def register_all_checkers_and_plugins(linter: PyLinter) -> None:
Expand Down
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 tests/config/functional/ini/pylintrc_with_deleted_message.ini
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
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
}
Loading