Commit 25de842f authored by Björn Dahlgren's avatar Björn Dahlgren Committed by Stefan Behnel

Update docs wrt property syntax deprecation

parent f5c02d3d
...@@ -81,7 +81,7 @@ Methods ...@@ -81,7 +81,7 @@ Methods
Properties Properties
========== ==========
* Cython provides a special syntax:: * Cython provides a special (deprecated) syntax::
cdef class Spam: cdef class Spam:
...@@ -120,7 +120,7 @@ Properties ...@@ -120,7 +120,7 @@ Properties
def __cinit__(self): def __cinit__(self):
self.cheeses = [] self.cheeses = []
property cheese: property cheese: # note that this syntax is deprecated
def __get__(self): def __get__(self):
return "We don't have: %s" % self.cheeses return "We don't have: %s" % self.cheeses
......
...@@ -138,9 +138,10 @@ Attributes in cdef classes behave differently from attributes in regular classes ...@@ -138,9 +138,10 @@ Attributes in cdef classes behave differently from attributes in regular classes
# Available in Python-space: # Available in Python-space:
cdef public double freq cdef public double freq
# Available in Python-space: # Available in Python-space:
property period: @property
def __get__(self): def period(self):
return 1.0 / self.freq return 1.0 / self.freq
def __set__(self, value): @period.setter
self.freq = 1.0 / value def period(self, value):
self.freq = 1.0 / value
<...> <...>
...@@ -223,7 +223,26 @@ extension types. ...@@ -223,7 +223,26 @@ extension types.
Properties 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: cdef class Spam:
...@@ -259,16 +278,17 @@ when it is deleted.:: ...@@ -259,16 +278,17 @@ when it is deleted.::
def __cinit__(self): def __cinit__(self):
self.cheeses = [] self.cheeses = []
property cheese: @property
def cheese(self):
return "We don't have: %s" % self.cheeses
def __get__(self): @cheese.setter
return "We don't have: %s" % self.cheeses def cheese(self):
self.cheeses.append(value)
def __set__(self, value): @cheese.deleter
self.cheeses.append(value) def cheese(self):
del self.cheeses[:]
def __del__(self):
del self.cheeses[:]
# Test input # Test input
from cheesy import CheeseShop from cheesy import CheeseShop
......
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