Skip to content

Commit

Permalink
Use existing consume helper and UNIMPORTANT_WS constant
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Feb 14, 2023
1 parent 52b1291 commit cd44676
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/django_upgrade/fixers/test_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from tokenize_rt import Offset
from tokenize_rt import Token
from tokenize_rt import UNIMPORTANT_WS

from django_upgrade.ast import ast_start_offset
from django_upgrade.compat import str_removeprefix
Expand All @@ -19,6 +20,7 @@
from django_upgrade.data import TokenFunc
from django_upgrade.fixers.assert_form_error import looks_like_client_call
from django_upgrade.tokens import CODE
from django_upgrade.tokens import consume
from django_upgrade.tokens import find
from django_upgrade.tokens import NAME
from django_upgrade.tokens import OP
Expand Down Expand Up @@ -120,19 +122,10 @@ def erase_keyword_argument(
value_start_idx = find(tokens, kwarg_name_start_idx, name=OP, src="=")
erased_tokens = tokens[value_start_idx + 1 : arg_end_idx]

ends_with_comma = (
tokens[arg_end_idx].name == OP and tokens[arg_end_idx].src == ","
)
if ends_with_comma:
arg_end_idx += 1
ends_with_whitespace = (
tokens[arg_end_idx].name == "UNIMPORTANT_WS"
and tokens[arg_end_idx].src == " "
)
if ends_with_whitespace:
arg_end_idx += 1
arg_end_idx = consume(tokens, arg_end_idx - 1, name=OP, src=",")
arg_end_idx = consume(tokens, arg_end_idx, name=UNIMPORTANT_WS)

del tokens[kwarg_name_start_idx:arg_end_idx]
del tokens[kwarg_name_start_idx : arg_end_idx + 1]
return erased_tokens, kwarg_name_start_idx
return [], -1

Expand Down

0 comments on commit cd44676

Please sign in to comment.