<@U06RKAMK0UC> Can a task have None as input arg e...
# ask-ai
w
@ancient-wolf-19325 Can a task have None as input arg e.g.
Copy code
@task
def some_task(some_num: int | None):
  pass
j
Yes, Flyte tasks can accept None as an input argument by using Optional types (e.g., int | None or typing.Optional[int]). This is supported in both task and workflow definitions, and None will be passed as expected if not specified or explicitly set to None. However, you must provide a default value of None in the function signature to make the argument truly optional; otherwise, Flyte will require the input at execution time. For example:
Copy code
from typing import Optional
from flytekit import task

@task
def some_task(some_num: Optional[int] = None):
    pass
According to Support for Optional value types in Tasks and Flyte Technical Summary, this pattern is supported, but you should avoid using mutable default arguments (like lists or dicts) as defaults. Would you like more detail or examples on how this works in workflows? Sources: - Support for Optional value types in Tasks - Flyte Technical Summary 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.