You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -34,12 +35,18 @@ All the other metadata of the created function are defined as follows:
34
35
-`__annotations__` attribute is created to match the annotations in the signature.
35
36
-`__doc__` attribute is copied from `func_impl.__doc__` except if overridden using `doc`
36
37
-`__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>`.
37
39
38
40
Finally two new attributes are optionally created
39
41
40
42
-`__source__` attribute: set if `add_source` is `True` (default), this attribute contains the source code of the generated function
41
43
-`__func_impl__` attribute: set if `add_impl` is `True` (default), this attribute contains a pointer to `func_impl`
42
44
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>`.
43
50
44
51
**Parameters:**
45
52
@@ -58,7 +65,9 @@ Finally two new attributes are optionally created
58
65
*`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.
59
66
60
67
*`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
+
62
71
*`module_name`: the name of the module to be set on the function (under __module__ ). If None (default), `func_impl.__module__` will be used.
63
72
64
73
*`attrs`: other keyword attributes that should be set on the function. Note that `func_impl.__dict__` is not automatically copied.
@@ -104,7 +114,9 @@ is totally equivalent to `impl = create_function(<arguments>, func_impl=impl)` e
104
114
*`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.
105
115
106
116
*`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
+
108
120
*`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.
109
121
110
122
*`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,
124
136
add_impl: bool=True,
125
137
doc: str=None,
126
138
qualname: str=None,
139
+
co_name: str=None,
127
140
module_name: str=None,
128
141
**attrs
129
142
):
@@ -180,7 +193,9 @@ See also [python documentation on @wraps](https://docs.python.org/3/library/func
180
193
-`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.
181
194
182
195
-`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
+
184
199
-`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.
185
200
186
201
-`attrs`: other keyword attributes that should be set on the function. Note that the full `__dict__` of `wrapped_fun` is automatically copied.
0 commit comments