File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 2
2
Usage
3
3
=====
4
4
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
6
10
7
- import variants
Original file line number Diff line number Diff line change @@ -99,11 +99,13 @@ def primary(f):
99
99
100
100
Decorate the main form of the function with this decorator, and then
101
101
subsequent variants should be declared with the same name as the original
102
- function.
102
+ function [#]_:
103
103
104
- .. example::
104
+ .. code-block:: python
105
105
106
- @variants
106
+ import variants
107
+
108
+ @variants.primary
107
109
def myfunc(fpath):
108
110
with open(fpath, 'r') as f:
109
111
do_something(f.read())
@@ -112,6 +114,18 @@ def myfunc(fpath):
112
114
def myfunc(url):
113
115
r = requests.get(url)
114
116
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.
115
129
"""
116
130
f_out = variant_wraps (VariantFunction (f ))
117
131
You can’t perform that action at this time.
0 commit comments