12
>>> class1().bplus1(1)
27
>>> cls = nested_class()
35
def __new__(cls): # implicit staticmethod
36
return object.__new__(cls)
44
cdef class BaseClass(object):
46
Test cdef static methods with super() and Python subclasses
49
>>> obj.mystaticmethod(obj, 1)
51
>>> BaseClass.mystaticmethod(obj, 1)
53
>>> obj.mystaticmethod2(1, 2, 3)
55
>>> BaseClass.mystaticmethod2(1, 2, 3)
60
def mystaticmethod(self, arg1):
65
def mystaticmethod2(a, b, c):
69
cdef class SubClass(BaseClass):
72
>>> obj.mystaticmethod(obj, 1)
75
>>> SubClass.mystaticmethod(obj, 1)
81
def mystaticmethod(self, arg1):
83
super().mystaticmethod(self, arg1 + 1)
86
class SubSubClass(SubClass):
88
>>> obj = SubSubClass()
89
>>> obj.mystaticmethod(obj, 1)
93
>>> SubSubClass.mystaticmethod(obj, 1)
100
def mystaticmethod(self, arg1):
102
super().mystaticmethod(self, arg1 + 1)
105
cdef class ArgsKwargs(object):
107
def with_first_arg(arg1, *args, **kwargs):
109
>>> ArgsKwargs().with_first_arg(1, 2, 3, a=4, b=5)
110
(1, 'pos', 2, 3, ('a', 4), ('b', 5))
112
return (arg1, 'pos') + args + tuple(sorted(kwargs.items()))
115
def only_args_kwargs(*args, **kwargs):
117
>>> ArgsKwargs().only_args_kwargs()
119
>>> ArgsKwargs().only_args_kwargs(1, 2, a=3)
122
return args + tuple(sorted(kwargs.items()))
127
>>> ArgsKwargs().no_args()
133
class StaticmethodSubclass(staticmethod):
135
>>> s = StaticmethodSubclass(None)
139
def is_subtype(self):
140
return isinstance(self, staticmethod)