Skip to content

Commit

Permalink
Delete token range
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Feb 11, 2024
1 parent 0f9ba24 commit 5c0b991
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/django_upgrade/fixers/request_user_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@ def rewrite_user_attribute(tokens: list[Token], i: int, *, attr: str) -> None:
j = find(tokens, i, name=NAME, src=attr)
y = find(tokens, j, name=OP, src="(")
z = find(tokens, y, name=OP, src=")")
del tokens[z]
del tokens[y]
del tokens[y : z + 1]
17 changes: 15 additions & 2 deletions tests/fixers/test_request_user_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,28 @@ def test_if_self_request_user_is_authenticated():

def test_spaces_between_noop():
check_noop(
"request . user . is_authenticated ",
"request . user . is_authenticated ",
settings,
)


def test_spaces_between():
check_transformed(
"request . user . is_authenticated ( )",
"request . user . is_authenticated ",
"request . user . is_authenticated ",
settings,
)


def test_comment_between():
check_transformed(
"""\
request.user.is_anonymous( # something
)
""",
"""\
request.user.is_anonymous
""",
settings,
)

Expand Down

0 comments on commit 5c0b991

Please sign in to comment.