Skip to content

Commit 5bdd503

Browse files
Add a test to check that no old msgid or symbol are used (#5839)
* Add deleted msgid and symbol from the Python 3K+ checker and other deleted checks. See #4942 Closes #5729 Co-authored-by: Daniël van Noord <[email protected]>
1 parent 15040ee commit 5bdd503

File tree

7 files changed

+146
-5
lines changed

7 files changed

+146
-5
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Release date: TBA
99
..
1010
Put new features here and also in 'doc/whatsnew/2.13.rst'
1111

12+
* ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids
13+
were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disabling using these msgids will break.
14+
This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and
15+
``basestring-builtin`` from the now deleted python 3K+ checker. There is now a check that we're not using
16+
existing msgids or symbols from deleted checkers.
17+
18+
Closes #5729
19+
1220
* Add ``--recursive`` option to allow recursive discovery of all modules and packages in subtree. Running pylint with
1321
``--recursive=y`` option will check all discovered ``.py`` files and packages found inside subtree of directory provided
1422
as parameter to pylint.

doc/whatsnew/2.13.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ Extensions
9292
Other Changes
9393
=============
9494

95+
* ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids
96+
were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disables using these msgids will break.
97+
This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and
98+
``basestring-builtin`` from the now deleted python 3K+ checker. There is now a check that we're not using
99+
existing msgids or symbols from deleted checkers.
100+
101+
Closes #5729
102+
95103
* Add ``--recursive`` option to allow recursive discovery of all modules and packages in subtree. Running pylint with
96104
``--recursive=y`` option will check all discovered ``.py`` files and packages found inside subtree of directory provided
97105
as parameter to pylint.

pylint/checkers/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@
3737
13: string_format
3838
14: string_constant
3939
15: stdlib
40-
16: python3
40+
16: python3 (This one was deleted but needs to be reserved for consistency with old messages)
4141
17: refactoring
4242
.
4343
.
4444
.
4545
24: non-ascii-names
4646
25: unicode
47-
26-50: not yet used: reserved for future internal checkers.
47+
26: unsupported_version
48+
27-50: not yet used: reserved for future internal checkers.
4849
This file is not updated. Use
4950
script/get_unused_message_id_category.py
5051
to get the next free checker id.

pylint/checkers/unsupported_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class UnsupportedVersionChecker(BaseChecker):
3535
__implements__ = (IAstroidChecker,)
3636
name = "unsupported_version"
3737
msgs = {
38-
"W1601": (
38+
"W2601": (
3939
"F-strings are not supported by all versions included in the py-version setting",
4040
"using-f-string-in-unsupported-version",
4141
"Used when the py-version set by the user is lower than 3.6 and pylint encounters "
4242
"a f-string.",
4343
),
44-
"W1602": (
44+
"W2602": (
4545
"typing.final is not supported by all versions included in the py-version setting",
4646
"using-final-decorator-in-unsupported-version",
4747
"Used when the py-version set by the user is lower than 3.8 and pylint encounters "

pylint/constants.py

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
import platform
44
import sys
5-
from typing import Dict
5+
from typing import Dict, List, NamedTuple, Tuple
66

77
import astroid
88
import platformdirs
@@ -72,3 +72,107 @@ class WarningScope:
7272
"class_const": "class constant",
7373
"inlinevar": "inline iteration",
7474
}
75+
76+
77+
class DeletedMessage(NamedTuple):
78+
msgid: str
79+
symbol: str
80+
old_names: List[Tuple[str, str]] = []
81+
82+
83+
DELETED_MSGID_PREFIXES = [
84+
16, # the PY3K+ checker, see https://github.com/PyCQA/pylint/pull/4942
85+
]
86+
87+
DELETED_MESSAGES = [
88+
# Everything until the next comment is from the
89+
# PY3K+ checker, see https://github.com/PyCQA/pylint/pull/4942
90+
DeletedMessage("W1601", "apply-builtin"),
91+
DeletedMessage("E1601", "print-statement"),
92+
DeletedMessage("E1602", "parameter-unpacking"),
93+
DeletedMessage(
94+
"E1603", "unpacking-in-except", [("W0712", "old-unpacking-in-except")]
95+
),
96+
DeletedMessage("E1604", "old-raise-syntax", [("W0121", "old-old-raise-syntax")]),
97+
DeletedMessage("E1605", "backtick", [("W0333", "old-backtick")]),
98+
DeletedMessage("E1609", "import-star-module-level"),
99+
DeletedMessage("W1601", "apply-builtin"),
100+
DeletedMessage("W1602", "basestring-builtin"),
101+
DeletedMessage("W1603", "buffer-builtin"),
102+
DeletedMessage("W1604", "cmp-builtin"),
103+
DeletedMessage("W1605", "coerce-builtin"),
104+
DeletedMessage("W1606", "execfile-builtin"),
105+
DeletedMessage("W1607", "file-builtin"),
106+
DeletedMessage("W1608", "long-builtin"),
107+
DeletedMessage("W1609", "raw_input-builtin"),
108+
DeletedMessage("W1610", "reduce-builtin"),
109+
DeletedMessage("W1611", "standarderror-builtin"),
110+
DeletedMessage("W1612", "unicode-builtin"),
111+
DeletedMessage("W1613", "xrange-builtin"),
112+
DeletedMessage("W1614", "coerce-method"),
113+
DeletedMessage("W1615", "delslice-method"),
114+
DeletedMessage("W1616", "getslice-method"),
115+
DeletedMessage("W1617", "setslice-method"),
116+
DeletedMessage("W1618", "no-absolute-import"),
117+
DeletedMessage("W1619", "old-division"),
118+
DeletedMessage("W1620", "dict-iter-method"),
119+
DeletedMessage("W1621", "dict-view-method"),
120+
DeletedMessage("W1622", "next-method-called"),
121+
DeletedMessage("W1623", "metaclass-assignment"),
122+
DeletedMessage(
123+
"W1624", "indexing-exception", [("W0713", "old-indexing-exception")]
124+
),
125+
DeletedMessage("W1625", "raising-string", [("W0701", "old-raising-string")]),
126+
DeletedMessage("W1626", "reload-builtin"),
127+
DeletedMessage("W1627", "oct-method"),
128+
DeletedMessage("W1628", "hex-method"),
129+
DeletedMessage("W1629", "nonzero-method"),
130+
DeletedMessage("W1630", "cmp-method"),
131+
DeletedMessage("W1632", "input-builtin"),
132+
DeletedMessage("W1633", "round-builtin"),
133+
DeletedMessage("W1634", "intern-builtin"),
134+
DeletedMessage("W1635", "unichr-builtin"),
135+
DeletedMessage(
136+
"W1636", "map-builtin-not-iterating", [("W1631", "implicit-map-evaluation")]
137+
),
138+
DeletedMessage("W1637", "zip-builtin-not-iterating"),
139+
DeletedMessage("W1638", "range-builtin-not-iterating"),
140+
DeletedMessage("W1639", "filter-builtin-not-iterating"),
141+
DeletedMessage("W1640", "using-cmp-argument"),
142+
DeletedMessage("W1641", "eq-without-hash"),
143+
DeletedMessage("W1642", "div-method"),
144+
DeletedMessage("W1643", "idiv-method"),
145+
DeletedMessage("W1644", "rdiv-method"),
146+
DeletedMessage("W1645", "exception-message-attribute"),
147+
DeletedMessage("W1646", "invalid-str-codec"),
148+
DeletedMessage("W1647", "sys-max-int"),
149+
DeletedMessage("W1648", "bad-python3-import"),
150+
DeletedMessage("W1649", "deprecated-string-function"),
151+
DeletedMessage("W1650", "deprecated-str-translate-call"),
152+
DeletedMessage("W1651", "deprecated-itertools-function"),
153+
DeletedMessage("W1652", "deprecated-types-field"),
154+
DeletedMessage("W1653", "next-method-defined"),
155+
DeletedMessage("W1654", "dict-items-not-iterating"),
156+
DeletedMessage("W1655", "dict-keys-not-iterating"),
157+
DeletedMessage("W1656", "dict-values-not-iterating"),
158+
DeletedMessage("W1657", "deprecated-operator-function"),
159+
DeletedMessage("W1658", "deprecated-urllib-function"),
160+
DeletedMessage("W1659", "xreadlines-attribute"),
161+
DeletedMessage("W1660", "deprecated-sys-function"),
162+
DeletedMessage("W1661", "exception-escape"),
163+
DeletedMessage("W1662", "comprehension-escape"),
164+
# https://github.com/PyCQA/pylint/pull/3578
165+
DeletedMessage("W0312", "mixed-indentation"),
166+
# https://github.com/PyCQA/pylint/pull/3577
167+
DeletedMessage(
168+
"C0326",
169+
"bad-whitespace",
170+
[
171+
("C0323", "no-space-after-operator"),
172+
("C0324", "no-space-after-comma"),
173+
("C0322", "no-space-before-operator"),
174+
],
175+
),
176+
# https://github.com/PyCQA/pylint/pull/3571
177+
DeletedMessage("C0330", "bad-continuation"),
178+
]

script/get_unused_message_id_category.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import List
66

77
from pylint.checkers import initialize as initialize_checkers
8+
from pylint.constants import DELETED_MSGID_PREFIXES
89
from pylint.extensions import initialize as initialize_extensions
910
from pylint.lint.pylinter import PyLinter
1011

@@ -18,6 +19,8 @@ def register_all_checkers_and_plugins(linter: "PyLinter") -> None:
1819

1920
def get_next_code_category(message_ids: List[str]) -> int:
2021
categories = sorted({int(i[:2]) for i in message_ids})
22+
# We add the prefixes for deleted checkers
23+
categories += DELETED_MSGID_PREFIXES
2124
for i in categories:
2225
if i + 1 not in categories:
2326
return i + 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2+
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3+
4+
from pylint.constants import DELETED_MESSAGES
5+
from pylint.lint import PyLinter
6+
7+
8+
def test_no_removed_msgid_or_symbol_used(linter: PyLinter) -> None:
9+
"""Tests that we're not using deleted msgid or symbol.
10+
11+
This could cause occasional bugs, but more importantly confusion and inconsistencies
12+
when searching for old msgids online. See https://github.com/PyCQA/pylint/issues/5729
13+
"""
14+
for msgid, symbol, old_names in DELETED_MESSAGES:
15+
linter.msgs_store.message_id_store.register_message_definition(
16+
msgid, symbol, old_names
17+
)

0 commit comments

Comments
 (0)