From 0c5469b672c936982127311f124c5edce7c48f7e Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 5 Sep 2020 09:13:35 +0200 Subject: [PATCH] Add typing to pylint.refactoring._is_trailing_comma --- .../checkers/refactoring/refactoring_checker.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index 96bd672698..e359c38a4d 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -8,6 +8,7 @@ import itertools import tokenize from functools import reduce +from typing import List import astroid from astroid import decorators @@ -22,14 +23,14 @@ BUILTIN_EXIT_FUNCS = frozenset(("quit", "exit")) -def _if_statement_is_always_returning(if_node, returning_node_class): +def _if_statement_is_always_returning(if_node, returning_node_class) -> bool: for node in if_node.body: if isinstance(node, returning_node_class): return True return False -def _is_trailing_comma(tokens, index): +def _is_trailing_comma(tokens: List[tokenize.TokenInfo], index: int) -> bool: """Check if the given token is a trailing comma :param tokens: Sequence of modules tokens @@ -43,11 +44,14 @@ def _is_trailing_comma(tokens, index): return False # Must have remaining tokens on the same line such as NEWLINE left_tokens = itertools.islice(tokens, index + 1, None) + + def same_start_token( + other_token: tokenize.TokenInfo, _token: tokenize.TokenInfo = token + ) -> bool: + return other_token.start[0] == _token.start[0] + same_line_remaining_tokens = list( - itertools.takewhile( - lambda other_token, _token=token: other_token.start[0] == _token.start[0], - left_tokens, - ) + itertools.takewhile(same_start_token, left_tokens) ) # Note: If the newline is tokenize.NEWLINE and not tokenize.NL # then the newline denotes the end of expression