diff options
author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2022-10-16 21:06:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-16 21:06:46 +0200 |
commit | 5d7e8f40067920c1e7f386d26bf918d7768b8f5b (patch) | |
tree | 55d0eb0fd0c72eab748dd5aeb7d0ceef68f77390 /pylint/extensions | |
parent | 00b6aa8482f007090c7b5224cf8e2ac42f34eec6 (diff) | |
download | pylint-git-5d7e8f40067920c1e7f386d26bf918d7768b8f5b.tar.gz |
Move `consider-using-augmented-assign` to `CodeStyle` extension (#7628)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/extensions')
-rw-r--r-- | pylint/extensions/code_style.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pylint/extensions/code_style.py b/pylint/extensions/code_style.py index 6acdb83d8..f9a17d005 100644 --- a/pylint/extensions/code_style.py +++ b/pylint/extensions/code_style.py @@ -11,6 +11,7 @@ from astroid import nodes from pylint.checkers import BaseChecker, utils from pylint.checkers.utils import only_required_for_messages, safe_infer +from pylint.interfaces import INFERENCE if TYPE_CHECKING: from pylint.lint import PyLinter @@ -58,6 +59,13 @@ class CodeStyleChecker(BaseChecker): "both can be combined by using an assignment expression ``:=``. " "Requires Python 3.8 and ``py-version >= 3.8``.", ), + "R6104": ( + "Use '%s' to do an augmented assign directly", + "consider-using-augmented-assign", + "Emitted when an assignment is referring to the object that it is assigning " + "to. This can be changed to be an augmented assign.\n" + "Disabled by default!", + ), } options = ( ( @@ -301,6 +309,21 @@ class CodeStyleChecker(BaseChecker): return True return False + @only_required_for_messages("consider-using-augmented-assign") + def visit_assign(self, node: nodes.Assign) -> None: + is_aug, op = utils.is_augmented_assign(node) + if is_aug: + self.add_message( + "consider-using-augmented-assign", + args=f"{op}=", + node=node, + line=node.lineno, + col_offset=node.col_offset, + confidence=INFERENCE, + ) + def register(linter: PyLinter) -> None: linter.register_checker(CodeStyleChecker(linter)) + # Disable some checks by default + linter.disable("consider-using-augmented-assign") |