Skip to content

Commit

Permalink
Remove assign-to-new-keyword (#6421)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Apr 21, 2022
1 parent e087b41 commit 4668f63
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 57 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -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.)
Expand Down
6 changes: 6 additions & 0 deletions doc/whatsnew/2.14.rst
Expand Up @@ -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
==========

Expand Down
35 changes: 2 additions & 33 deletions pylint/checkers/base/name_checker/checker.py
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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."""
Expand Down
2 changes: 2 additions & 0 deletions pylint/constants.py
Expand Up @@ -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"),
]


Expand Down
13 changes: 0 additions & 13 deletions tests/functional/a/assign_to_new_keyword.py

This file was deleted.

7 changes: 0 additions & 7 deletions tests/functional/a/assign_to_new_keyword.rc

This file was deleted.

4 changes: 0 additions & 4 deletions tests/functional/a/assign_to_new_keyword.txt

This file was deleted.

0 comments on commit 4668f63

Please sign in to comment.