Commit c7f4ce39 authored by Stefan Behnel's avatar Stefan Behnel

test __new__() optimisation interaction with __cinit__()

parent a32b90c2
...@@ -2,18 +2,27 @@ ...@@ -2,18 +2,27 @@
cimport cython cimport cython
cdef class MyType: cdef class MyType:
def __cinit__(self):
print "CINIT"
def __init__(self): def __init__(self):
print "INIT" print "INIT"
cdef class MySubType(MyType): cdef class MySubType(MyType):
def __cinit__(self):
print "CINIT(SUB)"
def __init__(self): def __init__(self):
print "INIT" print "INIT"
class MyClass(object): class MyClass(object):
def __cinit__(self):
print "CINIT"
def __init__(self): def __init__(self):
print "INIT" print "INIT"
class MyTypeSubClass(MyType): class MyTypeSubClass(MyType):
def __cinit__(self):
# not called: Python class!
print "CINIT(PYSUB)"
def __init__(self): def __init__(self):
print "INIT" print "INIT"
...@@ -24,6 +33,7 @@ class MyTypeSubClass(MyType): ...@@ -24,6 +33,7 @@ class MyTypeSubClass(MyType):
def make_new(): def make_new():
""" """
>>> isinstance(make_new(), MyType) >>> isinstance(make_new(), MyType)
CINIT
True True
""" """
m = MyType.__new__(MyType) m = MyType.__new__(MyType)
...@@ -34,6 +44,7 @@ def make_new(): ...@@ -34,6 +44,7 @@ def make_new():
def make_new_typed_target(): def make_new_typed_target():
""" """
>>> isinstance(make_new_typed_target(), MyType) >>> isinstance(make_new_typed_target(), MyType)
CINIT
True True
""" """
cdef MyType m cdef MyType m
...@@ -70,6 +81,7 @@ def make_new_none(type t=None): ...@@ -70,6 +81,7 @@ def make_new_none(type t=None):
def make_new_pyclass(): def make_new_pyclass():
""" """
>>> isinstance(make_new_pyclass(), MyTypeSubClass) >>> isinstance(make_new_pyclass(), MyTypeSubClass)
CINIT
True True
""" """
m = MyClass.__new__(MyClass) m = MyClass.__new__(MyClass)
...@@ -81,10 +93,13 @@ def make_new_pyclass(): ...@@ -81,10 +93,13 @@ def make_new_pyclass():
def make_new_args(type t1=None, type t2=None): def make_new_args(type t1=None, type t2=None):
""" """
>>> isinstance(make_new_args(), MyType) >>> isinstance(make_new_args(), MyType)
CINIT
True True
>>> isinstance(make_new_args(MyType), MyType) >>> isinstance(make_new_args(MyType), MyType)
CINIT
True True
>>> isinstance(make_new_args(MyType, MyType), MyType) >>> isinstance(make_new_args(MyType, MyType), MyType)
CINIT
True True
>>> isinstance(make_new_args(MyType, MySubType), MySubType) >>> isinstance(make_new_args(MyType, MySubType), MySubType)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment