Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r88811:d1edc5aca1da Date: 2016-12-02 10:52 +0100 http://bitbucket.org/pypy/pypy/changeset/d1edc5aca1da/
Log: Minimal changes to pass these tests 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 @@ -213,7 +213,7 @@ try: role_here = self.roles[name] except KeyError: - if name in bound: + if bound and name in bound: self.symbols[name] = SCOPE_FREE self.free_vars[name] = None else: @@ -330,7 +330,7 @@ return misc.mangle(name, self.name) def _pass_special_names(self, local, new_bound): - assert '__class__' in local + #assert '__class__' in local new_bound['__class__'] = None def _finalize_cells(self, free): @@ -485,7 +485,9 @@ def visit_Global(self, glob): for name in glob.names: old_role = self.scope.lookup_role(name) - if old_role & (SYM_USED | SYM_ASSIGNED): + if (old_role & (SYM_USED | SYM_ASSIGNED) and not + (name == '__class__' and + self.scope._hide_bound_from_nested_scopes)): if old_role & SYM_ASSIGNED: msg = "name '%s' is assigned to before global declaration" \ % (name,) @@ -499,7 +501,9 @@ def visit_Nonlocal(self, nonl): for name in nonl.names: old_role = self.scope.lookup_role(name) - if old_role & (SYM_USED | SYM_ASSIGNED): + if (old_role & (SYM_USED | SYM_ASSIGNED) and not + (name == '__class__' and + self.scope._hide_bound_from_nested_scopes)): if old_role & SYM_ASSIGNED: msg = "name '%s' is assigned to before nonlocal declaration" \ % (name,) diff --git a/pypy/interpreter/test/test_compiler.py b/pypy/interpreter/test/test_compiler.py --- a/pypy/interpreter/test/test_compiler.py +++ b/pypy/interpreter/test/test_compiler.py @@ -399,8 +399,11 @@ class X: nonlocal __class__ __class__ = 42 + assert locals()['__class__'] == 42 + # ^^^ but at the same place, reading '__class__' gives a NameError + # in CPython 3.5.2. Looks like a bug to me def testing(): - return 42 # 'Y.__class__' is *not* set to 42, at least on CPython 3.5.2 + return 42 ''' ]: space.call_args(w_filterwarnings, filter_arg) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit