Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor existing code - code_style extension #4872

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions pylint/extensions/code_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ def visit_dict(self, node: nodes.Dict) -> None:

@check_messages("consider-using-tuple")
def visit_for(self, node: nodes.For) -> None:
self._check_inplace_defined_list(node)
if isinstance(node.iter, nodes.List):
self.add_message("consider-using-tuple", node=node.iter)

@check_messages("consider-using-tuple")
def visit_comprehension(self, node: nodes.Comprehension) -> None:
self._check_inplace_defined_list(node)
if isinstance(node.iter, nodes.List):
self.add_message("consider-using-tuple", node=node.iter)

def _check_dict_consider_namedtuple_dataclass(self, node: nodes.Dict) -> None:
"""Check if dictionary values can be replaced by Namedtuple or Dataclass."""
Expand Down Expand Up @@ -133,13 +135,6 @@ def _check_dict_consider_namedtuple_dataclass(self, node: nodes.Dict) -> None:
self.add_message("consider-using-namedtuple-or-dataclass", node=node)
return

def _check_inplace_defined_list(
self, node: Union[nodes.For, nodes.Comprehension]
) -> None:
"""Check if in-place defined list can be replaced by a tuple."""
if isinstance(node.iter, nodes.List):
self.add_message("consider-using-tuple", node=node.iter)


def register(linter: PyLinter) -> None:
linter.register_checker(CodeStyleChecker(linter))