Skip to content

Docs updates #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ help:
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

autobuild:
sphinx-autobuild -p 9999 -b html "$(SOURCEDIR)" $(BUILDDIR)/html
sphinx-autobuild --port 9999 -b html "$(SOURCEDIR)" $(BUILDDIR)/html
25 changes: 24 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ Implementors are not required to implement methods with defaults:
# get_all(self) will automatically be copied from the interface default.

Default implementations should always be implemented in terms of other
interface methods.
interface methods. This ensures that the default is valid for any
implementation of the interface.

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

Default Properties
******************

:class:`default` and :class:`property` can be used together to create default properties:

.. code-block:: python

class ReadOnlyMappingWithSpecialKey(interface.Interface):

def get(self, key):
pass

@interface.default
@property
def special_key(self):
return self.get('special_key')

.. note::

The order of decorators in the example above is important: ``@default`` must
go above ``@property``.

Interface Subclassing
~~~~~~~~~~~~~~~~~~~~~

Expand Down