Skip to content

Commit 58db188

Browse files
authored
Merge pull request #46 from ssanderson/docs-updates
Docs updates
2 parents 022a4ab + cfd40c4 commit 58db188

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ help:
2020
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2121

2222
autobuild:
23-
sphinx-autobuild -p 9999 -b html "$(SOURCEDIR)" $(BUILDDIR)/html
23+
sphinx-autobuild --port 9999 -b html "$(SOURCEDIR)" $(BUILDDIR)/html

docs/usage.rst

+24-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ Implementors are not required to implement methods with defaults:
137137
# get_all(self) will automatically be copied from the interface default.
138138
139139
Default implementations should always be implemented in terms of other
140-
interface methods.
140+
interface methods. This ensures that the default is valid for any
141+
implementation of the interface.
141142

142143
In Python 3, :class:`default` will show a warning if a default implementation
143144
uses non-interface members of an object:
@@ -173,6 +174,28 @@ of ``get_all``:
173174
Consider changing ReadOnlyMapping.get_all or making these attributes part of ReadOnlyMapping.
174175
class ReadOnlyMapping(interface.Interface):
175176

177+
Default Properties
178+
******************
179+
180+
:class:`default` and :class:`property` can be used together to create default properties:
181+
182+
.. code-block:: python
183+
184+
class ReadOnlyMappingWithSpecialKey(interface.Interface):
185+
186+
def get(self, key):
187+
pass
188+
189+
@interface.default
190+
@property
191+
def special_key(self):
192+
return self.get('special_key')
193+
194+
.. note::
195+
196+
The order of decorators in the example above is important: ``@default`` must
197+
go above ``@property``.
198+
176199
Interface Subclassing
177200
~~~~~~~~~~~~~~~~~~~~~
178201

0 commit comments

Comments
 (0)