Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.6 Changeset: r95539:26c82f5c208f Date: 2018-12-30 13:17 +0100 http://bitbucket.org/pypy/pypy/changeset/26c82f5c208f/
Log: The variable annotation: '(var): int' should consider (var) as an expression, and not cause var to become a local variable. diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py --- a/pypy/interpreter/astcompiler/symtable.py +++ b/pypy/interpreter/astcompiler/symtable.py @@ -429,11 +429,15 @@ self.scope.contains_annotated = True target = assign.target if isinstance(target, ast.Name): - scope = SYM_ANNOTATED + # XXX Should check (and fail) for previous 'global' annotation. name = target.id + scope = SYM_BLANK + if assign.simple: + scope |= SYM_ANNOTATED if assign.value: scope |= SYM_USED - self.note_symbol(name, scope) + if scope: + self.note_symbol(name, scope) else: target.walkabout(self) if assign.value is not None: diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py b/pypy/interpreter/astcompiler/test/test_symtable.py --- a/pypy/interpreter/astcompiler/test/test_symtable.py +++ b/pypy/interpreter/astcompiler/test/test_symtable.py @@ -517,6 +517,9 @@ fscp = self.func_scope("def f(): implicit_global[0]: int") assert fscp.lookup("implicit_global") == symtable.SCOPE_GLOBAL_IMPLICIT + fscp = self.func_scope("def f(): (implicit_global): int") + assert fscp.lookup("implicit_global") == symtable.SCOPE_UNKNOWN + def test_issue13343(self): scp = self.mod_scope("lambda *, k1=x, k2: None") assert scp.lookup("x") == symtable.SCOPE_GLOBAL_IMPLICIT diff --git a/pypy/interpreter/test/test_annotations.py b/pypy/interpreter/test/test_annotations.py --- a/pypy/interpreter/test/test_annotations.py +++ b/pypy/interpreter/test/test_annotations.py @@ -73,6 +73,15 @@ ... ''' + def test_non_simple_func_annotation(self): + ''' + a = 5 + def f(): + (a): int + return a + assert f() == 5 + ''' + def test_repeated_setup(self): # each exec will run another SETUP_ANNOTATIONS # we want to confirm that this doesn't blow away @@ -147,4 +156,3 @@ """ c = compile(s, "f", "exec") assert c.co_firstlineno == 3 - _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit