diff options
author | Jeroen Demeyer <jdemeyer@cage.ugent.be> | 2018-12-31 13:55:15 +0100 |
---|---|---|
committer | Jeroen Demeyer <jdemeyer@cage.ugent.be> | 2019-01-01 09:56:39 +0100 |
commit | 5b2513aa83e2d08bbf6f29ed34d6a50b90116a9d (patch) | |
tree | 94d0b932b4883eaeac326df7df2d456c75dc7859 | |
parent | 8e7406a087cc9ffe8a190cf6867dd2b90f22fad2 (diff) | |
download | cython-5b2513aa83e2d08bbf6f29ed34d6a50b90116a9d.tar.gz |
Only generate __qualname__ in Python versions supporting it
-rw-r--r-- | Cython/Utility/ObjectHandling.c | 4 | ||||
-rwxr-xr-x | runtests.py | 1 | ||||
-rw-r--r-- | tests/run/decorators_T593.pyx | 4 | ||||
-rw-r--r-- | tests/run/locals_T732.pyx | 4 | ||||
-rw-r--r-- | tests/run/metaclass.pyx | 16 |
5 files changed, 17 insertions, 12 deletions
diff --git a/Cython/Utility/ObjectHandling.c b/Cython/Utility/ObjectHandling.c index a90911142..8acc67bac 100644 --- a/Cython/Utility/ObjectHandling.c +++ b/Cython/Utility/ObjectHandling.c @@ -913,8 +913,10 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na if (PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0) return NULL; +#if PY_VERSION_HEX >= 0x03030000 if (PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0) return NULL; +#endif /* Python2 __metaclass__ */ metaclass = __Pyx_PyDict_GetItemStr(dict, PYIDENT("__metaclass__")); @@ -974,7 +976,9 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, /* Required here to emulate assignment order */ 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; +#endif if (unlikely(doc && PyObject_SetItem(ns, PYIDENT("__doc__"), doc) < 0)) goto bad; return ns; bad: diff --git a/runtests.py b/runtests.py index d187c5265..9f0f4a7db 100755 --- a/runtests.py +++ b/runtests.py @@ -428,6 +428,7 @@ VER_DEP_MODULES = { (3,3) : (operator.lt, lambda x: x in ['build.package_compilation', 'run.yield_from_py33', 'pyximport.pyximport_namespace', + 'run.qualname', ]), (3,4): (operator.lt, lambda x: x in ['run.py34_signature', 'run.test_unicode', # taken from Py3.7, difficult to backport diff --git a/tests/run/decorators_T593.pyx b/tests/run/decorators_T593.pyx index 9ac3508b8..2d87c4c31 100644 --- a/tests/run/decorators_T593.pyx +++ b/tests/run/decorators_T593.pyx @@ -110,8 +110,8 @@ class Base(type): class Bar(metaclass=Base): """ - >>> Bar._order - ['__module__', '__qualname__', '__doc__', 'bar'] + >>> [n for n in Bar._order if n != "__qualname__"] + ['__module__', '__doc__', 'bar'] """ @property def bar(self): diff --git a/tests/run/locals_T732.pyx b/tests/run/locals_T732.pyx index d134948af..6bae1d236 100644 --- a/tests/run/locals_T732.pyx +++ b/tests/run/locals_T732.pyx @@ -23,8 +23,8 @@ def test_class_locals_and_dir(): >>> klass = test_class_locals_and_dir() >>> 'visible' in klass.locs and 'not_visible' not in klass.locs True - >>> klass.names - ['__module__', '__qualname__', 'visible'] + >>> [n for n in klass.names if n != "__qualname__"] + ['__module__', 'visible'] """ not_visible = 1234 class Foo: diff --git a/tests/run/metaclass.pyx b/tests/run/metaclass.pyx index d5464fb17..26ac9af46 100644 --- a/tests/run/metaclass.pyx +++ b/tests/run/metaclass.pyx @@ -69,8 +69,8 @@ class Py3ClassMCOnly(object, metaclass=Py3MetaclassPlusAttr): 321 >>> obj.metaclass_was_here True - >>> obj._order - ['__module__', '__qualname__', '__doc__', 'bar', 'metaclass_was_here'] + >>> [n for n in obj._order if n != "__qualname__"] + ['__module__', '__doc__', 'bar', 'metaclass_was_here'] """ bar = 321 @@ -81,8 +81,8 @@ class Py3InheritedMetaclass(Py3ClassMCOnly): 345 >>> obj.metaclass_was_here True - >>> obj._order - ['__module__', '__qualname__', '__doc__', 'bar', 'metaclass_was_here'] + >>> [n for n in obj._order if n != "__qualname__"] + ['__module__', '__doc__', 'bar', 'metaclass_was_here'] """ bar = 345 @@ -109,8 +109,8 @@ class Py3Foo(object, metaclass=Py3Base, foo=123): 123 >>> obj.bar 321 - >>> obj._order - ['__module__', '__qualname__', '__doc__', 'bar', 'foo'] + >>> [n for n in obj._order if n != "__qualname__"] + ['__module__', '__doc__', 'bar', 'foo'] """ bar = 321 @@ -122,8 +122,8 @@ class Py3FooInherited(Py3Foo, foo=567): 567 >>> obj.bar 321 - >>> obj._order - ['__module__', '__qualname__', '__doc__', 'bar', 'foo'] + >>> [n for n in obj._order if n != "__qualname__"] + ['__module__', '__doc__', 'bar', 'foo'] """ bar = 321 |