From 4668f636ece4c4286310ebc90c9a15ffbe0c1b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 21 Apr 2022 11:16:52 +0200 Subject: [PATCH] Remove ``assign-to-new-keyword`` (#6421) --- ChangeLog | 5 +++ doc/whatsnew/2.14.rst | 6 ++++ pylint/checkers/base/name_checker/checker.py | 35 ++------------------ pylint/constants.py | 2 ++ tests/functional/a/assign_to_new_keyword.py | 13 -------- tests/functional/a/assign_to_new_keyword.rc | 7 ---- tests/functional/a/assign_to_new_keyword.txt | 4 --- 7 files changed, 15 insertions(+), 57 deletions(-) delete mode 100644 tests/functional/a/assign_to_new_keyword.py delete mode 100644 tests/functional/a/assign_to_new_keyword.rc delete mode 100644 tests/functional/a/assign_to_new_keyword.txt diff --git a/ChangeLog b/ChangeLog index d94308343d..d07386b515 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,11 @@ Release date: TBA Closes #5224 +* Removed the ``assign-to-new-keyword`` message as there are no new keywords in the supported Python + versions any longer. + + Closes #4683 + * Fixed failure to enable ``deprecated-module`` after a ``disable=all`` by making ``ImportsChecker`` solely responsible for emitting ``deprecated-module`` instead of sharing responsibility with ``StdlibChecker``. (This could have led to double messages.) diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst index c1c7d19409..afa590bb28 100644 --- a/doc/whatsnew/2.14.rst +++ b/doc/whatsnew/2.14.rst @@ -61,6 +61,12 @@ Removed checkers Closes #2409 +* Removed the ``assign-to-new-keyword`` message as there are no new keywords in the supported Python + versions any longer. + + Closes #4683 + + Extensions ========== diff --git a/pylint/checkers/base/name_checker/checker.py b/pylint/checkers/base/name_checker/checker.py index 1241597bde..0fdb1b43d4 100644 --- a/pylint/checkers/base/name_checker/checker.py +++ b/pylint/checkers/base/name_checker/checker.py @@ -173,12 +173,6 @@ class NameChecker(_BasicChecker): "Emitted when a TypeVar is assigned to a variable " "that does not match its name argument.", ), - "W0111": ( - "Name %s will become a keyword in Python %s", - "assign-to-new-keyword", - "Used when assignment will become invalid in future " - "Python release due to introducing new keyword.", - ), } options = ( @@ -258,8 +252,6 @@ class NameChecker(_BasicChecker): ), ) + _create_naming_options() - KEYWORD_ONSET = {(3, 7): {"async", "await"}} - def __init__(self, linter): super().__init__(linter) self._name_category = {} @@ -340,19 +332,17 @@ def leave_module(self, _: nodes.Module) -> None: for args in warnings: self._raise_name_warning(prevalent_group, *args) - @utils.check_messages("disallowed-name", "invalid-name", "assign-to-new-keyword") + @utils.check_messages("disallowed-name", "invalid-name") def visit_classdef(self, node: nodes.ClassDef) -> None: - self._check_assign_to_new_keyword_violation(node.name, node) self._check_name("class", node.name, node) for attr, anodes in node.instance_attrs.items(): if not any(node.instance_attr_ancestors(attr)): self._check_name("attr", attr, anodes[0]) - @utils.check_messages("disallowed-name", "invalid-name", "assign-to-new-keyword") + @utils.check_messages("disallowed-name", "invalid-name") def visit_functiondef(self, node: nodes.FunctionDef) -> None: # Do not emit any warnings if the method is just an implementation # of a base class method. - self._check_assign_to_new_keyword_violation(node.name, node) confidence = interfaces.HIGH if node.is_method(): if utils.overrides_a_method(node.parent.frame(future=True), node.name): @@ -384,14 +374,12 @@ def visit_global(self, node: nodes.Global) -> None: @utils.check_messages( "disallowed-name", "invalid-name", - "assign-to-new-keyword", "typevar-name-incorrect-variance", "typevar-double-variance", "typevar-name-mismatch", ) def visit_assignname(self, node: nodes.AssignName) -> None: """Check module level assigned names.""" - self._check_assign_to_new_keyword_violation(node.name, node) frame = node.frame(future=True) assign_type = node.assign_type() @@ -541,25 +529,6 @@ def _should_exempt_from_invalid_name(node): if node_type == "typevar": self._check_typevar(name, node) - def _check_assign_to_new_keyword_violation(self, name, node): - keyword_first_version = self._name_became_keyword_in_version( - name, self.KEYWORD_ONSET - ) - if keyword_first_version is not None: - self.add_message( - "assign-to-new-keyword", - node=node, - args=(name, keyword_first_version), - confidence=interfaces.HIGH, - ) - - @staticmethod - def _name_became_keyword_in_version(name, rules): - for version, keywords in rules.items(): - if name in keywords and sys.version_info < version: - return ".".join(str(v) for v in version) - return None - @staticmethod def _assigns_typevar(node: nodes.NodeNG | None) -> bool: """Check if a node is assigning a TypeVar.""" diff --git a/pylint/constants.py b/pylint/constants.py index 2fe436579b..7b5081d64e 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -186,6 +186,8 @@ class DeletedMessage(NamedTuple): 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"), ] diff --git a/tests/functional/a/assign_to_new_keyword.py b/tests/functional/a/assign_to_new_keyword.py deleted file mode 100644 index c5a23ca95a..0000000000 --- a/tests/functional/a/assign_to_new_keyword.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Tests for assign-to-new-keyword""" -# pylint: disable=missing-function-docstring, missing-class-docstring, too-few-public-methods, function-redefined - -async = "foo" # [assign-to-new-keyword] -await = "bar" # [assign-to-new-keyword] - - -def async(): # [assign-to-new-keyword] - pass - - -class async: # [assign-to-new-keyword] - pass diff --git a/tests/functional/a/assign_to_new_keyword.rc b/tests/functional/a/assign_to_new_keyword.rc deleted file mode 100644 index d83e35df82..0000000000 --- a/tests/functional/a/assign_to_new_keyword.rc +++ /dev/null @@ -1,7 +0,0 @@ -[BASIC] -const-rgx=.+ -function-rgx=.+ -class-rgx=.+ - -[testoptions] -max_pyver=3.7 diff --git a/tests/functional/a/assign_to_new_keyword.txt b/tests/functional/a/assign_to_new_keyword.txt deleted file mode 100644 index c6c92c1dd7..0000000000 --- a/tests/functional/a/assign_to_new_keyword.txt +++ /dev/null @@ -1,4 +0,0 @@ -assign-to-new-keyword:4:None:4:None::Name async will become a keyword in Python 3.7:HIGH -assign-to-new-keyword:5:None:5:None::Name await will become a keyword in Python 3.7:HIGH -assign-to-new-keyword:8:None:8:None:async:Name async will become a keyword in Python 3.7:HIGH -assign-to-new-keyword:12:None:12:None:async:Name async will become a keyword in Python 3.7:HIGH