From c3d71b958dccfe6537a4553492fc9dac352ab983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Mon, 13 Sep 2021 21:56:24 +0200 Subject: [PATCH] move to xfail --- pyupgrade/_plugins/versioned_branches.py | 7 +----- tests/features/versioned_branches_test.py | 27 +++++++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pyupgrade/_plugins/versioned_branches.py b/pyupgrade/_plugins/versioned_branches.py index 002ad03d..6cc7a1c4 100644 --- a/pyupgrade/_plugins/versioned_branches.py +++ b/pyupgrade/_plugins/versioned_branches.py @@ -188,10 +188,5 @@ def visit_If( ): if node.orelse and not isinstance(node.orelse[0], ast.If): yield ast_to_offset(node), _fix_py3_block_else - elif not node.orelse and min_version == (3, 0): - # allow >= (3,) and > (3,) to be dedented even without - # an else clause, as a special cases + elif not node.orelse: yield ast_to_offset(node), _fix_py3_block - else: - # don't try to fix, e.g., >= (3, 6) if there's no else clause - yield ast_to_offset(node), lambda i, tokens: None diff --git a/tests/features/versioned_branches_test.py b/tests/features/versioned_branches_test.py index 82272569..dd583750 100644 --- a/tests/features/versioned_branches_test.py +++ b/tests/features/versioned_branches_test.py @@ -555,15 +555,6 @@ def test_fix_py3x_only_code(s, expected): @pytest.mark.parametrize( 's', ( - # we timidly skip `if` without `else` as it could cause a SyntaxError - 'import sys\n' - 'if sys.version_info >= (3, 6):\n' - ' pass', - # here's the case where it causes a SyntaxError - 'import sys\n' - 'if True:\n' - ' if sys.version_info >= (3, 6):\n' - ' pass\n', # both branches are still relevant in the following cases 'import sys\n' 'if sys.version_info > (3, 7):\n' @@ -600,7 +591,25 @@ def test_fix_py3x_only_code(s, expected): ' 3+7\n' 'else:\n' ' 3-6\n', + + # this one *could* be fixed, it's just not implemented yet + # see test_no_else_py3x_only_code + 'import sys\n' + 'if sys.version_info >= (3, 6):\n' + ' pass', ), ) def test_fix_py3x_only_noop(s): assert _fix_plugins(s, settings=Settings(min_version=(3, 6))) == s + + +@pytest.mark.xfail(reason='not implemented') +def test_no_else_py3x_only_code(): + + s = ( + 'import sys\n' + 'if sys.version_info >= (3, 6):\n' + ' pass' + ) + expected = 'import sys\n' + assert _fix_plugins(s, settings=Settings(min_version=(3, 6))) == expected