Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r88813:e4f05423a1ff Date: 2016-12-02 11:18 +0100 http://bitbucket.org/pypy/pypy/changeset/e4f05423a1ff/
Log: Partly revert and complain on seeing 'global __class__' inside a class body. This is not what CPython does, but I don't understand how CPython works and I think it's too much of a special case (and, mostly, not tested at all) 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 @@ -485,9 +485,13 @@ def visit_Global(self, glob): for name in glob.names: old_role = self.scope.lookup_role(name) - if (old_role & (SYM_USED | SYM_ASSIGNED) and not - (name == '__class__' and - self.scope._hide_bound_from_nested_scopes)): + if (self.scope._hide_bound_from_nested_scopes and + name == '__class__'): + msg = ("'global __class__' inside a class statement is not " + "implemented in PyPy") + raise SyntaxError(msg, glob.lineno, glob.col_offset, + filename=self.compile_info.filename) + if old_role & (SYM_USED | SYM_ASSIGNED): if old_role & SYM_ASSIGNED: msg = "name '%s' is assigned to before global declaration" \ % (name,) diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py --- a/pypy/interpreter/astcompiler/test/test_compiler.py +++ b/pypy/interpreter/astcompiler/test/test_compiler.py @@ -1127,10 +1127,12 @@ source = """if 1: class X: global __class__ - def f(self): - super() """ py.test.raises(SyntaxError, self.simple_test, source, None, None) + # XXX this raises "'global __class__' inside a class statement + # is not implemented in PyPy". The reason it is not is that it + # seems we need to refactor some things to implement it exactly + # like CPython, and I seriously don't think there is a point def test_error_message_1(self): source = """if 1: 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 @@ -381,12 +381,6 @@ filter_arg = Arguments(space, [ space.wrap('error') ], ["module"], [space.wrap("<tmp>")]) for code in [''' -class C: - global __class__ - __class__ = 42 -def testing(): - return __class__ -''', ''' def testing(): __class__ = 0 def f(): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit