summaryrefslogtreecommitdiff
path: root/docs/examples/userguide/extension_types/c_property.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/userguide/extension_types/c_property.pyx')
-rw-r--r--docs/examples/userguide/extension_types/c_property.pyx20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/examples/userguide/extension_types/c_property.pyx b/docs/examples/userguide/extension_types/c_property.pyx
new file mode 100644
index 000000000..b759ceec1
--- /dev/null
+++ b/docs/examples/userguide/extension_types/c_property.pyx
@@ -0,0 +1,20 @@
+cdef extern from "complexobject.h":
+
+ struct Py_complex:
+ double real
+ double imag
+
+ ctypedef class __builtin__.complex [object PyComplexObject]:
+ cdef Py_complex cval
+
+ @property
+ cdef inline double real(self):
+ return self.cval.real
+
+ @property
+ cdef inline double imag(self):
+ return self.cval.imag
+
+
+def cprint(complex c):
+ print(f"{c.real :.4f}{c.imag :+.4f}j") # uses C calls to the above property methods.