Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
f3f00195
Commit
f3f00195
authored
Jun 12, 2016
by
scoder
Committed by
GitHub
Jun 12, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #505 from bjodah/doc-updates-property
Update docs wrt property syntax deprecation
parents
dd15594f
fbe97f7f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
16 deletions
+37
-16
docs/src/reference/extension_types.rst
docs/src/reference/extension_types.rst
+2
-2
docs/src/tutorial/cdef_classes.rst
docs/src/tutorial/cdef_classes.rst
+6
-5
docs/src/userguide/extension_types.rst
docs/src/userguide/extension_types.rst
+29
-9
No files found.
docs/src/reference/extension_types.rst
View file @
f3f00195
...
...
@@ -81,7 +81,7 @@ Methods
Properties
==========
* Cython provides a special syntax::
* Cython provides a special
(deprecated)
syntax::
cdef class Spam:
...
...
@@ -120,7 +120,7 @@ Properties
def __cinit__(self):
self.cheeses = []
property cheese:
property cheese:
# note that this syntax is deprecated
def __get__(self):
return "We don't have: %s" % self.cheeses
...
...
docs/src/tutorial/cdef_classes.rst
View file @
f3f00195
...
...
@@ -138,9 +138,10 @@ Attributes in cdef classes behave differently from attributes in regular classes
# Available in Python-space:
cdef public double freq
# Available in Python-space:
property period:
def __get__(self):
return 1.0 / self.freq
def __set__(self, value):
self.freq = 1.0 / value
@property
def period(self):
return 1.0 / self.freq
@period.setter
def period(self, value):
self.freq = 1.0 / value
<...>
docs/src/userguide/extension_types.rst
View file @
f3f00195
...
...
@@ -223,7 +223,26 @@ extension types.
Properties
============
There is a special syntax for defining properties in an extension class::
You can declare properties in an extension class using the same syntax as in ordinary Python code::
cdef class Spam:
@property
def cheese(self):
# This is called when the property is read.
...
@cheese.setter
def cheese(self, value):
# This is called when the property is written.
...
@cheese.deleter
def cheese(self):
# This is called when the property is deleted.
There is also a special (deprecated) legacy syntax for defining properties in an extension class::
cdef class Spam:
...
...
@@ -259,16 +278,17 @@ when it is deleted.::
def __cinit__(self):
self.cheeses = []
property cheese:
@property
def cheese(self):
return "We don't have: %s" % self.cheeses
def __get__(self):
return "We don't have: %s" % self.cheeses
@cheese.setter
def cheese(self):
self.cheeses.append(value)
def __set__(self, value):
self.cheeses.append(value)
def __del__(self):
del self.cheeses[:]
@cheese.deleter
def cheese(self):
del self.cheeses[:]
# Test input
from cheesy import CheeseShop
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment