Skip to content

Commit

Permalink
[deleted messages] Refactor the constant to be able to give a reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Jun 4, 2022
1 parent bdd470d commit cb27a9f
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 120 deletions.
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
125 changes: 125 additions & 0 deletions pylint/message/deleted_message_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# 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 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"),
],
}
4 changes: 2 additions & 2 deletions 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 All @@ -21,7 +21,7 @@ def register_all_checkers_and_plugins(linter: PyLinter) -> None:
def get_next_code_category(message_ids: list[str]) -> int:
categories = sorted({int(i[:2]) for i in message_ids})
# We add the prefixes for deleted checkers
categories += DELETED_MSGID_PREFIXES
categories += _DELETED_MSGID_PREFIXES
for i in categories:
if i + 1 not in categories:
return i + 1
Expand Down
11 changes: 6 additions & 5 deletions tests/message/test_no_removed_msgid_or_symbol_used.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

from pylint.constants import DELETED_MESSAGES
from pylint.lint import PyLinter
from pylint.message.deleted_message_ids import _DELETED_MESSAGES_IDS


def test_no_removed_msgid_or_symbol_used(linter: PyLinter) -> None:
Expand All @@ -12,7 +12,8 @@ def test_no_removed_msgid_or_symbol_used(linter: PyLinter) -> None:
This could cause occasional bugs, but more importantly confusion and inconsistencies
when searching for old msgids online. See https://github.com/PyCQA/pylint/issues/5729
"""
for msgid, symbol, old_names in DELETED_MESSAGES:
linter.msgs_store.message_id_store.register_message_definition(
msgid, symbol, old_names
)
for deleted_messages in _DELETED_MESSAGES_IDS.values():
for msgid, symbol, old_names in deleted_messages:
linter.msgs_store.message_id_store.register_message_definition(
msgid, symbol, old_names
)

0 comments on commit cb27a9f

Please sign in to comment.