[pypy-commit] pypy py3.5: Do not update cls.__qualname__ when cls.__name__ is modified
rlamy
pypy.commits at gmail.com
Wed Dec 7 10:15:15 EST 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r88944:7eeb99850b83
Date: 2016-12-07 15:14 +0000
http://bitbucket.org/pypy/pypy/changeset/7eeb99850b83/
Log: Do not update cls.__qualname__ when cls.__name__ is modified
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -941,6 +941,22 @@
else:
assert False
+ def test_qualname(self):
+ A = type('A', (), {'__qualname__': 'B.C'})
+ assert A.__name__ == 'A'
+ assert A.__qualname__ == 'B.C'
+ raises(TypeError, type, 'A', (), {'__qualname__': b'B'})
+ assert A.__qualname__ == 'B.C'
+
+ A.__qualname__ = 'D.E'
+ assert A.__name__ == 'A'
+ assert A.__qualname__ == 'D.E'
+
+ C = type('C', (), {})
+ C.__name__ = 'A'
+ assert C.__name__ == 'A'
+ assert C.__qualname__ == 'C'
+
def test_compare(self):
class A(object):
pass
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -166,7 +166,7 @@
overridetypedef=None, force_new_layout=False):
self.space = space
self.name = name
- self.qualname = None
+ self.qualname = name.decode('utf-8')
self.bases_w = bases_w
self.dict_w = dict_w
self.hasdict = False
@@ -545,7 +545,7 @@
return result.decode('utf-8')
def getqualname(self, space):
- return self.qualname or self.getname(space)
+ return self.qualname
def add_subclass(self, w_subclass):
space = self.space
More information about the pypy-commit
mailing list