Skip to content

Commit 5b1d618

Browse files
author
Sylvain MARIE
committed
Updated api reference with latest API changes
1 parent 05247f0 commit 5b1d618

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

docs/api_reference.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def create_function(func_signature: Union[str, Signature],
1515
add_impl: bool = True,
1616
doc: str = None,
1717
qualname: str = None,
18+
co_name: str = None,
1819
module_name: str = None,
1920
**attrs):
2021
```
@@ -34,12 +35,18 @@ All the other metadata of the created function are defined as follows:
3435
- `__annotations__` attribute is created to match the annotations in the signature.
3536
- `__doc__` attribute is copied from `func_impl.__doc__` except if overridden using `doc`
3637
- `__module__` attribute is copied from `func_impl.__module__` except if overridden using `module_name`
38+
- `__code__.co_name` (see above) defaults to the same value as the above `__name__` attribute, except when that value is not a valid Python identifier, in which case it will be `<lambda>`. It can be overridden by providing a `co_name` that is either a valid Python identifier or `<lambda>`.
3739

3840
Finally two new attributes are optionally created
3941

4042
- `__source__` attribute: set if `add_source` is `True` (default), this attribute contains the source code of the generated function
4143
- `__func_impl__` attribute: set if `add_impl` is `True` (default), this attribute contains a pointer to `func_impl`
4244

45+
A lambda function will be created in the following cases:
46+
47+
- when `func_signature` is a `Signature` object and `func_impl` is itself a lambda function,
48+
- when the function name, either derived from a `func_signature` string, or given explicitly with `func_name`, is not a valid Python identifier, or
49+
- when the provided `co_name` is `<lambda>`.
4350

4451
**Parameters:**
4552

@@ -58,7 +65,9 @@ Finally two new attributes are optionally created
5865
* `doc`: a string representing the docstring that will be used to set the __doc__ attribute on the generated function. If None (default), the doc of func_impl will be used.
5966

6067
* `qualname`: a string representing the qualified name to be used. If None (default), the `__qualname__` will default to the one of `func_impl` if `func_signature` is a `Signature`, or to the name defined in `func_signature` if `func_signature` is a `str` and contains a non-empty name.
61-
68+
69+
* `co_name`: a string representing the name to be used in the compiled code of the function. If None (default), the `__code__.co_name` will default to the one of `func_impl` if `func_signature` is a `Signature`, or to the name defined in `func_signature` if `func_signature` is a `str` and contains a non-empty name.
70+
6271
* `module_name`: the name of the module to be set on the function (under __module__ ). If None (default), `func_impl.__module__` will be used.
6372

6473
* `attrs`: other keyword attributes that should be set on the function. Note that `func_impl.__dict__` is not automatically copied.
@@ -73,6 +82,7 @@ def with_signature(func_signature: Union[str, Signature],
7382
add_impl: bool = True,
7483
doc: str = None,
7584
qualname: str = None,
85+
co_name: str = None,
7686
module_name: str = None,
7787
**attrs
7888
):
@@ -104,7 +114,9 @@ is totally equivalent to `impl = create_function(<arguments>, func_impl=impl)` e
104114
* `doc`: a string representing the docstring that will be used to set the __doc__ attribute on the generated function. If None (default), the doc of the decorated function will be used.
105115

106116
* `qualname`: a string representing the qualified name to be used. If None (default), the `__qualname__` will default to the one of `func_impl` if `func_signature` is a `Signature`, or to the name defined in `func_signature` if `func_signature` is a `str` and contains a non-empty name.
107-
117+
118+
* `co_name`: a string representing the name to be used in the compiled code of the function. If None (default), the `__code__.co_name` will default to the one of `func_impl` if `func_signature` is a `Signature`, or to the name defined in `func_signature` if `func_signature` is a `str` and contains a non-empty name.
119+
108120
* `module_name`: the name of the module to be set on the function (under __module__ ). If None (default), the `__module__` attribute of the decorated function will be used.
109121

110122
* `attrs`: other keyword attributes that should be set on the function. Note that the full `__dict__` of the decorated function is not automatically copied.
@@ -124,6 +136,7 @@ def wraps(f,
124136
add_impl: bool = True,
125137
doc: str = None,
126138
qualname: str = None,
139+
co_name: str = None,
127140
module_name: str = None,
128141
**attrs
129142
):
@@ -180,7 +193,9 @@ See also [python documentation on @wraps](https://docs.python.org/3/library/func
180193
- `doc`: a string representing the docstring that will be used to set the __doc__ attribute on the generated function. If None (default), the doc of `wrapped_fun` will be used. If `wrapped_fun` is an instance of `functools.partial`, a special enhanced doc will be generated.
181194

182195
- `qualname`: a string representing the qualified name to be used. If None (default), the `__qualname__` will default to the one of `wrapped_fun`, or the one in `new_sig` if `new_sig` is provided as a string with a non-empty function name.
183-
196+
197+
- `co_name`: a string representing the name to be used in the compiled code of the function. If None (default), the `__code__.co_name` will default to the one of `func_impl` if `func_signature` is a `Signature`, or to the name defined in `func_signature` if `func_signature` is a `str` and contains a non-empty name.
198+
184199
- `module_name`: the name of the module to be set on the function (under __module__ ). If None (default), the `__module__` attribute of `wrapped_fun` will be used.
185200

186201
- `attrs`: other keyword attributes that should be set on the function. Note that the full `__dict__` of `wrapped_fun` is automatically copied.
@@ -201,6 +216,7 @@ def create_wrapper(wrapped,
201216
add_impl: bool = True,
202217
doc: str = None,
203218
qualname: str = None,
219+
co_name: str = None,
204220
module_name: str = None,
205221
**attrs
206222
):

0 commit comments

Comments
 (0)