summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/cdef_classes/wave_function.py
diff options
context:
space:
mode:
author0dminnimda <52697657+0dminnimda@users.noreply.github.com>2021-07-14 22:02:02 +0300
committerGitHub <noreply@github.com>2021-07-14 21:02:02 +0200
commit54fa2b822565fc9ddef89aa399eb7562d5b76f07 (patch)
tree1aa89d6a85ea296dc85721358dd0be782c36c539 /docs/examples/tutorial/cdef_classes/wave_function.py
parent696a1959b44ca9028d3f9468723b6b24335ad921 (diff)
downloadcython-54fa2b822565fc9ddef89aa399eb7562d5b76f07.tar.gz
docs: Pythonise the "Extension types (aka. cdef classes)" page (cdef_classes.rst) (GH-4232)
Diffstat (limited to 'docs/examples/tutorial/cdef_classes/wave_function.py')
-rw-r--r--docs/examples/tutorial/cdef_classes/wave_function.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/examples/tutorial/cdef_classes/wave_function.py b/docs/examples/tutorial/cdef_classes/wave_function.py
new file mode 100644
index 000000000..7ff59a762
--- /dev/null
+++ b/docs/examples/tutorial/cdef_classes/wave_function.py
@@ -0,0 +1,22 @@
+from cython.cimports.sin_of_square import Function
+
+@cython.cclass
+class WaveFunction(Function):
+
+ # Not available in Python-space:
+ offset: float
+
+ # Available in Python-space:
+ freq = cython.declare(cython.double, visibility='public')
+
+ # Available in Python-space, but only for reading:
+ scale = cython.declare(cython.double, visibility='readonly')
+
+ # Available in Python-space:
+ @property
+ def period(self):
+ return 1.0 / self.freq
+
+ @period.setter
+ def period(self, value):
+ self.freq = 1.0 / value