Update partial.bzl to generate better markdown (#309)
This commit is contained in:
parent
775f66fb28
commit
b053a5ae11
|
@ -1,3 +1,7 @@
|
||||||
|
<!-- Generated with Stardoc: http://skydoc.bazel.build -->
|
||||||
|
|
||||||
|
<a name="#partial.make"></a>
|
||||||
|
|
||||||
## partial.make
|
## partial.make
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
@ -76,13 +80,13 @@ call site kwarg:
|
||||||
func = partial.make(_foo, "Ben", make_location="Hollywood")
|
func = partial.make(_foo, "Ben", make_location="Hollywood")
|
||||||
partial.call(func, "Jennifer", call_location="Denver")
|
partial.call(func, "Jennifer", call_location="Denver")
|
||||||
```
|
```
|
||||||
|
|
||||||
Prints "Ben is from Hollywood and Jennifer is from Denver!".
|
Prints "Ben is from Hollywood and Jennifer is from Denver!".
|
||||||
|
|
||||||
```
|
```
|
||||||
partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
|
partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
|
||||||
```
|
```
|
||||||
|
|
||||||
Prints "Ben is from LA and Jennifer is from Denver!".
|
Prints "Ben is from LA and Jennifer is from Denver!".
|
||||||
|
|
||||||
Note that keyword args may not overlap with positional args, regardless of
|
Note that keyword args may not overlap with positional args, regardless of
|
||||||
|
@ -97,46 +101,19 @@ func = partial.make(foo, 1)
|
||||||
partial.call(func, x=2)
|
partial.call(func, x=2)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
<table class="params-table">
|
**PARAMETERS**
|
||||||
<colgroup>
|
|
||||||
<col class="col-param" />
|
|
||||||
<col class="col-description" />
|
|
||||||
</colgroup>
|
|
||||||
<tbody>
|
|
||||||
<tr id="partial.make-func">
|
|
||||||
<td><code>func</code></td>
|
|
||||||
<td>
|
|
||||||
required.
|
|
||||||
<p>
|
|
||||||
The function to be called.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr id="partial.make-args">
|
|
||||||
<td><code>args</code></td>
|
|
||||||
<td>
|
|
||||||
optional.
|
|
||||||
<p>
|
|
||||||
Positional arguments to be passed to function.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr id="partial.make-kwargs">
|
|
||||||
<td><code>kwargs</code></td>
|
|
||||||
<td>
|
|
||||||
optional.
|
|
||||||
<p>
|
|
||||||
Keyword arguments to be passed to function. Note that these can
|
|
||||||
be overridden at the call sites.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
|
| Name | Description | Default Value |
|
||||||
|
| :-------------: | :-------------: | :-------------: |
|
||||||
|
| func | The function to be called. | none |
|
||||||
|
| args | Positional arguments to be passed to function. | none |
|
||||||
|
| kwargs | Keyword arguments to be passed to function. Note that these can be overridden at the call sites. | none |
|
||||||
|
|
||||||
|
|
||||||
|
<a name="#partial.call"></a>
|
||||||
|
|
||||||
## partial.call
|
## partial.call
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
@ -145,44 +122,31 @@ partial.call(<a href="#partial.call-partial">partial</a>, <a href="#partial.call
|
||||||
|
|
||||||
Calls a partial created using `make`.
|
Calls a partial created using `make`.
|
||||||
|
|
||||||
### Parameters
|
**PARAMETERS**
|
||||||
|
|
||||||
<table class="params-table">
|
|
||||||
<colgroup>
|
| Name | Description | Default Value |
|
||||||
<col class="col-param" />
|
| :-------------: | :-------------: | :-------------: |
|
||||||
<col class="col-description" />
|
| partial | The partial to be called. | none |
|
||||||
</colgroup>
|
| args | Additional positional arguments to be appended to the ones given to make. | none |
|
||||||
<tbody>
|
| kwargs | Additional keyword arguments to augment and override the ones given to make. | none |
|
||||||
<tr id="partial.call-partial">
|
|
||||||
<td><code>partial</code></td>
|
|
||||||
<td>
|
<a name="#partial.is_instance"></a>
|
||||||
required.
|
|
||||||
<p>
|
## partial.is_instance
|
||||||
The partial to be called.
|
|
||||||
</p>
|
<pre>
|
||||||
</td>
|
partial.is_instance(<a href="#partial.is_instance-v">v</a>)
|
||||||
</tr>
|
</pre>
|
||||||
<tr id="partial.call-args">
|
|
||||||
<td><code>args</code></td>
|
Returns True if v is a partial created using `make`.
|
||||||
<td>
|
|
||||||
optional.
|
**PARAMETERS**
|
||||||
<p>
|
|
||||||
Additional positional arguments to be appended to the ones given to
|
|
||||||
make.
|
| Name | Description | Default Value |
|
||||||
</p>
|
| :-------------: | :-------------: | :-------------: |
|
||||||
</td>
|
| v | The value to check. | none |
|
||||||
</tr>
|
|
||||||
<tr id="partial.call-kwargs">
|
|
||||||
<td><code>kwargs</code></td>
|
|
||||||
<td>
|
|
||||||
optional.
|
|
||||||
<p>
|
|
||||||
Additional keyword arguments to augment and override the ones
|
|
||||||
given to make.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,16 +51,22 @@ def _make(func, *args, **kwargs):
|
||||||
A partial 'function' can be defined with positional args and kwargs:
|
A partial 'function' can be defined with positional args and kwargs:
|
||||||
|
|
||||||
# function with no args
|
# function with no args
|
||||||
|
```
|
||||||
def function1():
|
def function1():
|
||||||
...
|
...
|
||||||
|
```
|
||||||
|
|
||||||
# function with 2 args
|
# function with 2 args
|
||||||
|
```
|
||||||
def function2(arg1, arg2):
|
def function2(arg1, arg2):
|
||||||
...
|
...
|
||||||
|
```
|
||||||
|
|
||||||
# function with 2 args and keyword args
|
# function with 2 args and keyword args
|
||||||
|
```
|
||||||
def function3(arg1, arg2, x, y):
|
def function3(arg1, arg2, x, y):
|
||||||
...
|
...
|
||||||
|
```
|
||||||
|
|
||||||
The positional args passed to the function are the args passed into make
|
The positional args passed to the function are the args passed into make
|
||||||
followed by any additional positional args given to call. The below example
|
followed by any additional positional args given to call. The below example
|
||||||
|
@ -68,24 +74,30 @@ def _make(func, *args, **kwargs):
|
||||||
make and the other by call:
|
make and the other by call:
|
||||||
|
|
||||||
# function demonstrating 1 arg at make site, and 1 arg at call site
|
# function demonstrating 1 arg at make site, and 1 arg at call site
|
||||||
|
```
|
||||||
def _foo(make_arg1, func_arg1):
|
def _foo(make_arg1, func_arg1):
|
||||||
print(make_arg1 + " " + func_arg1 + "!")
|
print(make_arg1 + " " + func_arg1 + "!")
|
||||||
|
```
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
|
```
|
||||||
hi_func = partial.make(_foo, "Hello")
|
hi_func = partial.make(_foo, "Hello")
|
||||||
bye_func = partial.make(_foo, "Goodbye")
|
bye_func = partial.make(_foo, "Goodbye")
|
||||||
partial.call(hi_func, "Jennifer")
|
partial.call(hi_func, "Jennifer")
|
||||||
partial.call(hi_func, "Dave")
|
partial.call(hi_func, "Dave")
|
||||||
partial.call(bye_func, "Jennifer")
|
partial.call(bye_func, "Jennifer")
|
||||||
partial.call(bye_func, "Dave")
|
partial.call(bye_func, "Dave")
|
||||||
|
```
|
||||||
|
|
||||||
prints:
|
prints:
|
||||||
|
|
||||||
|
```
|
||||||
"Hello, Jennifer!"
|
"Hello, Jennifer!"
|
||||||
"Hello, Dave!"
|
"Hello, Dave!"
|
||||||
"Goodbye, Jennifer!"
|
"Goodbye, Jennifer!"
|
||||||
"Goodbye, Dave!"
|
"Goodbye, Dave!"
|
||||||
|
```
|
||||||
|
|
||||||
The keyword args given to the function are the kwargs passed into make
|
The keyword args given to the function are the kwargs passed into make
|
||||||
unioned with the keyword args given to call. In case of a conflict, the
|
unioned with the keyword args given to call. In case of a conflict, the
|
||||||
|
@ -95,16 +107,20 @@ def _make(func, *args, **kwargs):
|
||||||
Example with a make site arg, a call site arg, a make site kwarg and a
|
Example with a make site arg, a call site arg, a make site kwarg and a
|
||||||
call site kwarg:
|
call site kwarg:
|
||||||
|
|
||||||
|
```
|
||||||
def _foo(make_arg1, call_arg1, make_location, call_location):
|
def _foo(make_arg1, call_arg1, make_location, call_location):
|
||||||
print(make_arg1 + " is from " + make_location + " and " +
|
print(make_arg1 + " is from " + make_location + " and " +
|
||||||
call_arg1 + " is from " + call_location + "!")
|
call_arg1 + " is from " + call_location + "!")
|
||||||
|
|
||||||
func = partial.make(_foo, "Ben", make_location="Hollywood")
|
func = partial.make(_foo, "Ben", make_location="Hollywood")
|
||||||
partial.call(func, "Jennifer", call_location="Denver")
|
partial.call(func, "Jennifer", call_location="Denver")
|
||||||
|
```
|
||||||
|
|
||||||
Prints "Ben is from Hollywood and Jennifer is from Denver!".
|
Prints "Ben is from Hollywood and Jennifer is from Denver!".
|
||||||
|
|
||||||
|
```
|
||||||
partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
|
partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
|
||||||
|
```
|
||||||
|
|
||||||
Prints "Ben is from LA and Jennifer is from Denver!".
|
Prints "Ben is from LA and Jennifer is from Denver!".
|
||||||
|
|
||||||
|
@ -112,11 +128,13 @@ def _make(func, *args, **kwargs):
|
||||||
whether they are given during the make or call step. For instance, you can't
|
whether they are given during the make or call step. For instance, you can't
|
||||||
do:
|
do:
|
||||||
|
|
||||||
|
```
|
||||||
def foo(x):
|
def foo(x):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func = partial.make(foo, 1)
|
func = partial.make(foo, 1)
|
||||||
partial.call(func, x=2)
|
partial.call(func, x=2)
|
||||||
|
```
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
func: The function to be called.
|
func: The function to be called.
|
||||||
|
|
Loading…
Reference in New Issue