Skip to content

Commit e2926ab

Browse files
authored
Merge pull request #19 from pganssle/add_documentation
Add usage documentation
2 parents bc0f872 + ec434e7 commit e2926ab

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

docs/usage.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Usage
33
=====
44

5-
To use variants in a project::
5+
To use ``variants`` in a project, decorate the primary function with the ``@variants.primary``
6+
decorator, which will add the ``variant`` method to your original function.
7+
8+
.. module:: variants
9+
.. autofunction:: variants.primary
610

7-
import variants

src/variants/_variants.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ def primary(f):
9999
100100
Decorate the main form of the function with this decorator, and then
101101
subsequent variants should be declared with the same name as the original
102-
function.
102+
function [#]_:
103103
104-
.. example::
104+
.. code-block:: python
105105
106-
@variants
106+
import variants
107+
108+
@variants.primary
107109
def myfunc(fpath):
108110
with open(fpath, 'r') as f:
109111
do_something(f.read())
@@ -112,6 +114,18 @@ def myfunc(fpath):
112114
def myfunc(url):
113115
r = requests.get(url)
114116
do_something(r.text)
117+
118+
The ``primary`` decorator returns an object that attempts to transparently
119+
proxy the original methods of the original callable, but variants added to
120+
the primary function will shadow the original methods and attributes. Other
121+
than this, any valid python identifier is a valid name for a variant.
122+
123+
.. [#] Declaring subsequent variants with the same name as the original
124+
function is a stylistic convention, not a requirement. Decorating
125+
any function with the ``.variant`` decorator will mutate the primary
126+
function object, no matter the name of the variant function. However,
127+
whatever function you use for the variant function declaration will
128+
become an alias for the primary function.
115129
"""
116130
f_out = variant_wraps(VariantFunction(f))
117131

0 commit comments

Comments
 (0)