[pypy-commit] pypy py3.5: Test and fix (lib-python/3/test/test_descr)
arigo
pypy.commits at gmail.com
Wed Aug 23 11:56:45 EDT 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r92225:c1fb69da92dc
Date: 2017-08-23 17:56 +0200
http://bitbucket.org/pypy/pypy/changeset/c1fb69da92dc/
Log: Test and fix (lib-python/3/test/test_descr)
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
@@ -1284,6 +1284,25 @@
raises(ValueError, type, 'A\x00B', (), {})
raises(TypeError, type, b'A', (), {})
+ def test_incomplete_extend(self): """
+ # Extending an unitialized type with type.__mro__ is None must
+ # throw a reasonable TypeError exception, instead of failing
+ # with a segfault.
+ class M(type):
+ def mro(cls):
+ if cls.__mro__ is None and cls.__name__ != 'X':
+ try:
+ class X(cls):
+ pass
+ except TypeError:
+ found.append(1)
+ return type.mro(cls)
+ found = []
+ class A(metaclass=M):
+ pass
+ assert found == [1]
+ """
+
class AppTestWithMethodCacheCounter:
spaceconfig = {"objspace.std.withmethodcachecounter": True}
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
@@ -1055,6 +1055,9 @@
if w_bestbase is None:
raise oefmt(space.w_TypeError,
"a new-style class can't have only classic bases")
+ if not w_bestbase.hasmro:
+ raise oefmt(space.w_TypeError,
+ "Cannot extend an incomplete type '%N'", w_bestbase)
if not w_bestbase.layout.typedef.acceptable_as_base_class:
raise oefmt(space.w_TypeError,
"type '%N' is not an acceptable base class", w_bestbase)
More information about the pypy-commit
mailing list