-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Docs] Prevent using mutable default arguments in flytesnacks #5383
Comments
DescriptionMutable default arguments is a common anti-pattern in Python. See Mutable Default Arguments for details. We should prevent using it in flytesnacks. For example: Are you sure this issue hasn't been raised already?
Have you read the Code of Conduct?
Sources:
This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not. Mention @RunLLM to ask follow-up questions. See runllm.com for more! |
@MortalHappiness , please see flyteorg/flytesnacks#1685 (comment) and let me know what you think. OTOH, enabling this in flytekit should be a no-brainer. |
@eapolinario I still don't think it is a good pattern, especially in flytesnacks, which is the documentation for examples. Examples with anti-patterns may mislead users that are not proficient in Python to write these code. Actually, I found this problem when I was working on this PR: I know that if the default argument is used in workflow like the following: @task
def t1(a: list[int]) -> list[int]:
return a
@workflow
def wf(a: list[int] = [1, 2, 3]) -> list[int]:
a.append(4)
return t1(a=a) It will show that However, in the PR that I mentioned above, I need to handle the case of @task
def t1(a: list[int] = [1, 2, 3]) -> list[int]:
a.append(4)
return a
@workflow
def wf() -> list[int]:
t1()
return t1() Note that |
I agree but sadly the defaults are a way to specify defaults for default launchplans or workflows. |
Also worth mentioning that this problem only affects local executions (after we add support for default values for tasks). |
Addressed here flyteorg/flytekit#2443 |
Description
Mutable default arguments is a common anti-pattern in Python. See https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments for details. We should prevent using it in flytesnacks.
For example:
https://github.com/flyteorg/flytesnacks/blob/2d73e2a0892a56efc4fe3649db942e8270ccfe8c/examples/advanced_composition/advanced_composition/map_task.py#L13
Are you sure this issue hasn't been raised already?
Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: