Commit 5b2513aa authored by Jeroen Demeyer's avatar Jeroen Demeyer

Only generate __qualname__ in Python versions supporting it

parent 8e7406a0
...@@ -913,8 +913,10 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na ...@@ -913,8 +913,10 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na
if (PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0) if (PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0)
return NULL; return NULL;
#if PY_VERSION_HEX >= 0x03030000
if (PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0) if (PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0)
return NULL; return NULL;
#endif
/* Python2 __metaclass__ */ /* Python2 __metaclass__ */
metaclass = __Pyx_PyDict_GetItemStr(dict, PYIDENT("__metaclass__")); metaclass = __Pyx_PyDict_GetItemStr(dict, PYIDENT("__metaclass__"));
...@@ -974,7 +976,9 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, ...@@ -974,7 +976,9 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases,
/* Required here to emulate assignment order */ /* Required here to emulate assignment order */
if (unlikely(PyObject_SetItem(ns, PYIDENT("__module__"), modname) < 0)) goto bad; if (unlikely(PyObject_SetItem(ns, PYIDENT("__module__"), modname) < 0)) goto bad;
#if PY_VERSION_HEX >= 0x03030000
if (unlikely(PyObject_SetItem(ns, PYIDENT("__qualname__"), qualname) < 0)) goto bad; if (unlikely(PyObject_SetItem(ns, PYIDENT("__qualname__"), qualname) < 0)) goto bad;
#endif
if (unlikely(doc && PyObject_SetItem(ns, PYIDENT("__doc__"), doc) < 0)) goto bad; if (unlikely(doc && PyObject_SetItem(ns, PYIDENT("__doc__"), doc) < 0)) goto bad;
return ns; return ns;
bad: bad:
......
...@@ -428,6 +428,7 @@ VER_DEP_MODULES = { ...@@ -428,6 +428,7 @@ VER_DEP_MODULES = {
(3,3) : (operator.lt, lambda x: x in ['build.package_compilation', (3,3) : (operator.lt, lambda x: x in ['build.package_compilation',
'run.yield_from_py33', 'run.yield_from_py33',
'pyximport.pyximport_namespace', 'pyximport.pyximport_namespace',
'run.qualname',
]), ]),
(3,4): (operator.lt, lambda x: x in ['run.py34_signature', (3,4): (operator.lt, lambda x: x in ['run.py34_signature',
'run.test_unicode', # taken from Py3.7, difficult to backport 'run.test_unicode', # taken from Py3.7, difficult to backport
......
...@@ -110,8 +110,8 @@ class Base(type): ...@@ -110,8 +110,8 @@ class Base(type):
class Bar(metaclass=Base): class Bar(metaclass=Base):
""" """
>>> Bar._order >>> [n for n in Bar._order if n != "__qualname__"]
['__module__', '__qualname__', '__doc__', 'bar'] ['__module__', '__doc__', 'bar']
""" """
@property @property
def bar(self): def bar(self):
......
...@@ -23,8 +23,8 @@ def test_class_locals_and_dir(): ...@@ -23,8 +23,8 @@ def test_class_locals_and_dir():
>>> klass = test_class_locals_and_dir() >>> klass = test_class_locals_and_dir()
>>> 'visible' in klass.locs and 'not_visible' not in klass.locs >>> 'visible' in klass.locs and 'not_visible' not in klass.locs
True True
>>> klass.names >>> [n for n in klass.names if n != "__qualname__"]
['__module__', '__qualname__', 'visible'] ['__module__', 'visible']
""" """
not_visible = 1234 not_visible = 1234
class Foo: class Foo:
......
...@@ -69,8 +69,8 @@ class Py3ClassMCOnly(object, metaclass=Py3MetaclassPlusAttr): ...@@ -69,8 +69,8 @@ class Py3ClassMCOnly(object, metaclass=Py3MetaclassPlusAttr):
321 321
>>> obj.metaclass_was_here >>> obj.metaclass_was_here
True True
>>> obj._order >>> [n for n in obj._order if n != "__qualname__"]
['__module__', '__qualname__', '__doc__', 'bar', 'metaclass_was_here'] ['__module__', '__doc__', 'bar', 'metaclass_was_here']
""" """
bar = 321 bar = 321
...@@ -81,8 +81,8 @@ class Py3InheritedMetaclass(Py3ClassMCOnly): ...@@ -81,8 +81,8 @@ class Py3InheritedMetaclass(Py3ClassMCOnly):
345 345
>>> obj.metaclass_was_here >>> obj.metaclass_was_here
True True
>>> obj._order >>> [n for n in obj._order if n != "__qualname__"]
['__module__', '__qualname__', '__doc__', 'bar', 'metaclass_was_here'] ['__module__', '__doc__', 'bar', 'metaclass_was_here']
""" """
bar = 345 bar = 345
...@@ -109,8 +109,8 @@ class Py3Foo(object, metaclass=Py3Base, foo=123): ...@@ -109,8 +109,8 @@ class Py3Foo(object, metaclass=Py3Base, foo=123):
123 123
>>> obj.bar >>> obj.bar
321 321
>>> obj._order >>> [n for n in obj._order if n != "__qualname__"]
['__module__', '__qualname__', '__doc__', 'bar', 'foo'] ['__module__', '__doc__', 'bar', 'foo']
""" """
bar = 321 bar = 321
...@@ -122,8 +122,8 @@ class Py3FooInherited(Py3Foo, foo=567): ...@@ -122,8 +122,8 @@ class Py3FooInherited(Py3Foo, foo=567):
567 567
>>> obj.bar >>> obj.bar
321 321
>>> obj._order >>> [n for n in obj._order if n != "__qualname__"]
['__module__', '__qualname__', '__doc__', 'bar', 'foo'] ['__module__', '__doc__', 'bar', 'foo']
""" """
bar = 321 bar = 321
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment