[pypy-issue] Issue #1930: magic __class__ variable not defined in PyPy 3 (pypy/pypy)

Christopher Johnson issues-reply at bitbucket.org
Thu Nov 20 19:48:56 CET 2014


New issue 1930: magic __class__ variable not defined in PyPy 3
https://bitbucket.org/pypy/pypy/issue/1930/magic-__class__-variable-not-defined-in

Christopher Johnson:

In Python 3, the magic __class__ variable is supposed to be defined inside methods to refer to the class object where the methods are defined (NOT NECESSARILY the class of self).

PyPy3 does not yet implement this feature, which makes it out of sync with CPython 3.

Here is the output while running my test:

$ python2.7 pypy_class_bug.py
Traceback (most recent call last):
  File "pypy_class_bug.py", line 9, in <module>
    Derived().printBase() # on CPython prints "Base"
  File "pypy_class_bug.py", line 4, in printBase
    print(__class__.__name__)
NameError: global name '__class__' is not defined
$ python3.2 pypy_class_bug.py
Base
$ pypy2 pypy_class_bug.py
Traceback (most recent call last):
  File "app_main.py", line 75, in run_toplevel
  File "pypy_class_bug.py", line 9, in <module>
    Derived().printBase() # on CPython prints "Base"
  File "pypy_class_bug.py", line 4, in printBase
    print(__class__.__name__)
NameError: global name '__class__' is not defined
$ pypy3 pypy_class_bug.py
Traceback (most recent call last):
  File "pypy_class_bug.py", line 9, in <module>
    Derived().printBase() # on CPython prints "Base"
  File "pypy_class_bug.py", line 4, in printBase
    print(__class__.__name__)
NameError: global name '__class__' is not defined





More information about the pypy-issue mailing list