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,