From c7f4ce39b80be5c264caa3e889aec9cff40d5a25 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 1 Nov 2009 14:01:50 +0100 Subject: [PATCH] test __new__() optimisation interaction with __cinit__() --- tests/run/tp_new.pyx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/run/tp_new.pyx b/tests/run/tp_new.pyx index 01f06827..d98ee9a4 100644 --- a/tests/run/tp_new.pyx +++ b/tests/run/tp_new.pyx @@ -2,18 +2,27 @@ cimport cython cdef class MyType: + def __cinit__(self): + print "CINIT" def __init__(self): print "INIT" cdef class MySubType(MyType): + def __cinit__(self): + print "CINIT(SUB)" def __init__(self): print "INIT" class MyClass(object): + def __cinit__(self): + print "CINIT" def __init__(self): print "INIT" class MyTypeSubClass(MyType): + def __cinit__(self): + # not called: Python class! + print "CINIT(PYSUB)" def __init__(self): print "INIT" @@ -24,6 +33,7 @@ class MyTypeSubClass(MyType): def make_new(): """ >>> isinstance(make_new(), MyType) + CINIT True """ m = MyType.__new__(MyType) @@ -34,6 +44,7 @@ def make_new(): def make_new_typed_target(): """ >>> isinstance(make_new_typed_target(), MyType) + CINIT True """ cdef MyType m @@ -70,6 +81,7 @@ def make_new_none(type t=None): def make_new_pyclass(): """ >>> isinstance(make_new_pyclass(), MyTypeSubClass) + CINIT True """ m = MyClass.__new__(MyClass) @@ -81,10 +93,13 @@ def make_new_pyclass(): def make_new_args(type t1=None, type t2=None): """ >>> isinstance(make_new_args(), MyType) + CINIT True >>> isinstance(make_new_args(MyType), MyType) + CINIT True >>> isinstance(make_new_args(MyType, MyType), MyType) + CINIT True >>> isinstance(make_new_args(MyType, MySubType), MySubType) -- 2.26.2