Author: Armin Rigo <ar...@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) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit