Skip to content

Commit 98154b0

Browse files
authored
docs(Functions): clarify type annotation restrictions when using function_handle (#2639)
1 parent c3fbdfa commit 98154b0

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

cognite/client/_api/functions/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ async def create(
245245
.. note:
246246
When using a predefined function object, you can list dependencies between the tags `[requirements]` and `[/requirements]` in the function's docstring.
247247
The dependencies will be parsed and validated in accordance with requirement format specified in `PEP 508 <https://peps.python.org/pep-0508/>`_.
248+
249+
.. note:
250+
Only the source code of the handle function itself is deployed. Non-builtin type
251+
annotations (e.g. ``client: CogniteClient``) will cause a ``NameError`` at deploy
252+
time. Either omit the annotation or use string form (e.g. ``client: "CogniteClient"``).
248253
"""
249254
if isinstance(name, FunctionWrite):
250255
function_input = name

cognite/client/_sync_api/functions/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
===============================================================================
3-
9a58504453f212b9189304aa9ac90385
3+
cae4f37f697c159b6c87429edc9005ee
44
This file is auto-generated from the Async API modules, - do not edit manually!
55
===============================================================================
66
"""
@@ -214,6 +214,11 @@ def create(
214214
.. note:
215215
When using a predefined function object, you can list dependencies between the tags `[requirements]` and `[/requirements]` in the function's docstring.
216216
The dependencies will be parsed and validated in accordance with requirement format specified in `PEP 508 <https://peps.python.org/pep-0508/>`_.
217+
218+
.. note:
219+
Only the source code of the handle function itself is deployed. Non-builtin type
220+
annotations (e.g. ``client: CogniteClient``) will cause a ``NameError`` at deploy
221+
time. Either omit the annotation or use string form (e.g. ``client: "CogniteClient"``).
217222
"""
218223
return run_sync(
219224
self.__async_client.functions.create(

cognite/client/data_classes/functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ class FunctionHandle(Protocol):
4848
.. code-block:: python
4949
5050
def handle(
51-
client: CogniteClient | None = None,
51+
client: "CogniteClient",
5252
data: dict[str, object] | None = None,
5353
) -> object:
5454
# Do something with the data
5555
return {"result": "success"}
5656
57+
Note:
58+
Only the source code of the handle function itself is deployed. Non-builtin type
59+
annotations (e.g. ``CogniteClient``) will cause a ``NameError`` at deploy time.
60+
Either omit the annotation or use string form (e.g. ``client: "CogniteClient"``).
61+
5762
Returns:
5863
object: Return value of the function. Any JSON serializable object is allowed.
5964
"""

0 commit comments

Comments
 (0)