From c00e24af8a171011e3e771e29939585f877b58a1 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 9 Nov 2022 16:25:54 +0100 Subject: [PATCH] reverse check order --- pyupgrade/_plugins/typing_pep604.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pyupgrade/_plugins/typing_pep604.py b/pyupgrade/_plugins/typing_pep604.py index 85aee7c1..155d44c4 100644 --- a/pyupgrade/_plugins/typing_pep604.py +++ b/pyupgrade/_plugins/typing_pep604.py @@ -144,20 +144,18 @@ def visit_Subscript( if not _supported_version(state): return - # prevent rewriting forward annotations (unless they will be dequoted) - has_forward_annotation = ( - (sys.version_info >= (3, 9) and _any_arg_is_str(node.slice)) or - ( - sys.version_info < (3, 9) and - isinstance(node.slice, ast.Index) and - _any_arg_is_str(node.slice.value) + # don't rewrite forward annotations (unless we know they will be dequoted) + if 'annotations' not in state.from_imports['__future__']: + has_forward_annotation = ( + (sys.version_info >= (3, 9) and _any_arg_is_str(node.slice)) or + ( + sys.version_info < (3, 9) and + isinstance(node.slice, ast.Index) and + _any_arg_is_str(node.slice.value) + ) ) - ) - if ( - has_forward_annotation - and 'annotations' not in state.from_imports['__future__'] - ): - return + if has_forward_annotation: + return if is_name_attr( node.value,