diff --git a/ChangeLog b/ChangeLog index 6d1a12bcf8..e566e1da39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,14 @@ Release date: TBA .. Put new features here and also in 'doc/whatsnew/2.13.rst' +* ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids + were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disabling using these msgids will break. + This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and + ``basestring-builtin`` from the now deleted python 3K+ checker. There is now a check that we're not using + existing msgids or symbols from deleted checkers. + + Closes #5729 + * Add ``--recursive`` option to allow recursive discovery of all modules and packages in subtree. Running pylint with ``--recursive=y`` option will check all discovered ``.py`` files and packages found inside subtree of directory provided as parameter to pylint. diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index 676860ee54..580f0b69df 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -92,6 +92,14 @@ Extensions Other Changes ============= +* ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids + were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disables using these msgids will break. + This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and + ``basestring-builtin`` from the now deleted python 3K+ checker. There is now a check that we're not using + existing msgids or symbols from deleted checkers. + + Closes #5729 + * Add ``--recursive`` option to allow recursive discovery of all modules and packages in subtree. Running pylint with ``--recursive=y`` option will check all discovered ``.py`` files and packages found inside subtree of directory provided as parameter to pylint. diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index e99560faa3..a79a381941 100644 --- a/pylint/checkers/__init__.py +++ b/pylint/checkers/__init__.py @@ -37,14 +37,15 @@ 13: string_format 14: string_constant 15: stdlib -16: python3 +16: python3 (This one was deleted but needs to be reserved for consistency with old messages) 17: refactoring . . . 24: non-ascii-names 25: unicode -26-50: not yet used: reserved for future internal checkers. +26: unsupported_version +27-50: not yet used: reserved for future internal checkers. This file is not updated. Use script/get_unused_message_id_category.py to get the next free checker id. diff --git a/pylint/checkers/unsupported_version.py b/pylint/checkers/unsupported_version.py index b3369b877f..7c82817c00 100644 --- a/pylint/checkers/unsupported_version.py +++ b/pylint/checkers/unsupported_version.py @@ -35,13 +35,13 @@ class UnsupportedVersionChecker(BaseChecker): __implements__ = (IAstroidChecker,) name = "unsupported_version" msgs = { - "W1601": ( + "W2601": ( "F-strings are not supported by all versions included in the py-version setting", "using-f-string-in-unsupported-version", "Used when the py-version set by the user is lower than 3.6 and pylint encounters " "a f-string.", ), - "W1602": ( + "W2602": ( "typing.final is not supported by all versions included in the py-version setting", "using-final-decorator-in-unsupported-version", "Used when the py-version set by the user is lower than 3.8 and pylint encounters " diff --git a/pylint/constants.py b/pylint/constants.py index 813cd54dd8..c3b94863dc 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -2,7 +2,7 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE import platform import sys -from typing import Dict +from typing import Dict, List, NamedTuple, Tuple import astroid import platformdirs @@ -72,3 +72,107 @@ class WarningScope: "class_const": "class constant", "inlinevar": "inline iteration", } + + +class DeletedMessage(NamedTuple): + msgid: str + symbol: str + old_names: List[Tuple[str, str]] = [] + + +DELETED_MSGID_PREFIXES = [ + 16, # the PY3K+ checker, see https://github.com/PyCQA/pylint/pull/4942 +] + +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("W1641", "eq-without-hash"), + 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"), +] diff --git a/script/get_unused_message_id_category.py b/script/get_unused_message_id_category.py index 2741148c04..95d7ac3e30 100644 --- a/script/get_unused_message_id_category.py +++ b/script/get_unused_message_id_category.py @@ -5,6 +5,7 @@ from typing import List 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 @@ -18,6 +19,8 @@ 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 for i in categories: if i + 1 not in categories: return i + 1 diff --git a/tests/message/test_no_removed_msgid_or_symbol_used.py b/tests/message/test_no_removed_msgid_or_symbol_used.py new file mode 100644 index 0000000000..c6ece36794 --- /dev/null +++ b/tests/message/test_no_removed_msgid_or_symbol_used.py @@ -0,0 +1,17 @@ +# 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 + +from pylint.constants import DELETED_MESSAGES +from pylint.lint import PyLinter + + +def test_no_removed_msgid_or_symbol_used(linter: PyLinter) -> None: + """Tests that we're not using deleted msgid or symbol. + + 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 + )