Skip to content

Commit

Permalink
Add typing to pylint.refactoring._is_trailing_comma
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 5, 2020
1 parent 7d67d34 commit 0c5469b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import itertools
import tokenize
from functools import reduce
from typing import List

import astroid
from astroid import decorators
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0c5469b

Please sign in to comment.