Skip to content

Commit

Permalink
Support one element tuple in the versioned block fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownPlatypus committed Dec 15, 2024
1 parent 4e0e469 commit b93779d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/django_upgrade/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def is_passing_comparison(
and isinstance(test.ops[0], (ast.Gt, ast.GtE, ast.Lt, ast.LtE))
and len(test.comparators) == 1
and isinstance((comparator := test.comparators[0]), ast.Tuple)
and len(comparator.elts) == 2
and 0 < len(comparator.elts) <= 2
and all(isinstance(e, ast.Constant) for e in comparator.elts)
and all(isinstance(cast(ast.Constant, e).value, int) for e in comparator.elts)
):
Expand Down
44 changes: 44 additions & 0 deletions tests/fixers/test_versioned_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
check_transformed = partial(tools.check_transformed, settings=settings)


def test_empty_tuple():
check_noop(
"""\
import django
if django.VERSION > ():
foo()
""",
)


def test_future_version_gt():
check_noop(
"""\
Expand Down Expand Up @@ -263,3 +274,36 @@ def test_removed_block_internal_comment():
""",
)


def test_old_version_lt_single_tuple():
check_transformed(
"""\
import django
if django.VERSION < (4,):
foo()
bar()
""",
"""\
import django
bar()
""",
)


def test_current_version_gte_single_tuple():
check_transformed(
"""\
import django
if django.VERSION >= (4,):
foo()
""",
"""\
import django
foo()
""",
)

0 comments on commit b93779d

Please sign in to comment.