Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(170021)

Side by Side Diff: Doc/library/abc.rst

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/abc.py » ('j') | Lib/abc.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`abc` --- Abstract Base Classes 1 :mod:`abc` --- Abstract Base Classes
2 ==================================== 2 ====================================
3 3
4 .. module:: abc 4 .. module:: abc
5 :synopsis: Abstract base classes according to PEP 3119. 5 :synopsis: Abstract base classes according to PEP 3119.
6 .. moduleauthor:: Guido van Rossum 6 .. moduleauthor:: Guido van Rossum
7 .. sectionauthor:: Georg Brandl 7 .. sectionauthor:: Georg Brandl
8 .. much of the content adapted from docstrings 8 .. much of the content adapted from docstrings
9 9
10 **Source code:** :source:`Lib/abc.py` 10 **Source code:** :source:`Lib/abc.py`
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ... 155 ...
156 156
157 .. note:: 157 .. note::
158 158
159 Unlike Java abstract methods, these abstract 159 Unlike Java abstract methods, these abstract
160 methods may have an implementation. This implementation can be 160 methods may have an implementation. This implementation can be
161 called via the :func:`super` mechanism from the class that 161 called via the :func:`super` mechanism from the class that
162 overrides it. This could be useful as an end-point for a 162 overrides it. This could be useful as an end-point for a
163 super-call in a framework that uses cooperative 163 super-call in a framework that uses cooperative
164 multiple-inheritance. 164 multiple-inheritance.
165
166 .. versionchanged:: 3.3
durban 2011/03/19 21:36:09 The abstractmethod decorator isn't changed, so the
dsdale24 2011/03/19 22:13:42 This is really the best place for it. It doesn't b
167 The :func:`property` definition has been extended to allow
168 abstract properties to be specified using
169 :func:`abstractmethod`::
170
171 class C(metaclass=ABCMeta):
172 @property
173 @abstractmethod
174 def x(self):
175 ...
176 @x.setter
177 @abstractmethod
178 def x(self, val):
179 ...
180
181 @abstractmethod
182 def gety(self):
183 ...
184 @abstractmethod
185 def sety(self):
186 ...
187 y = property(gety, sety)
165 188
166 189
167 .. decorator:: abstractclassmethod(function) 190 .. decorator:: abstractclassmethod(function)
168 191
169 A subclass of the built-in :func:`classmethod`, indicating an abstract 192 A subclass of the built-in :func:`classmethod`, indicating an abstract
170 classmethod. Otherwise it is similar to :func:`abstractmethod`. 193 classmethod. Otherwise it is similar to :func:`abstractmethod`.
171 194
172 Usage:: 195 Usage::
173 196
174 class C(metaclass=ABCMeta): 197 class C(metaclass=ABCMeta):
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 def my_abstract_property(self): 235 def my_abstract_property(self):
213 ... 236 ...
214 237
215 This defines a read-only property; you can also define a read-write abstract 238 This defines a read-only property; you can also define a read-write abstract
216 property using the 'long' form of property declaration:: 239 property using the 'long' form of property declaration::
217 240
218 class C(metaclass=ABCMeta): 241 class C(metaclass=ABCMeta):
219 def getx(self): ... 242 def getx(self): ...
220 def setx(self, value): ... 243 def setx(self, value): ...
221 x = abstractproperty(getx, setx) 244 x = abstractproperty(getx, setx)
245
246 .. deprecated:: 3.3
durban 2011/03/19 21:36:09 I don't think abstractproperty should be deprecate
dsdale24 2011/03/19 22:13:42 Zen of python.
222 247
223 248
224 .. rubric:: Footnotes 249 .. rubric:: Footnotes
225 250
226 .. [#] C++ programmers should note that Python's virtual base class 251 .. [#] C++ programmers should note that Python's virtual base class
227 concept is not the same as C++'s. 252 concept is not the same as C++'s.
OLDNEW
« no previous file with comments | « no previous file | Lib/abc.py » ('j') | Lib/abc.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+