Skip to content

To review: Optional arrays/objects should not have side effects #6

@tcompa

Description

@tcompa

EDIT: The most compelling specific issue is now part of fractal-analytics-platform/fractal-tasks-core#448. This issue is now to track the broader discussion on how to proceed regarding:

  1. scope setting: which use cases will be supported in fractal-web? Where will this information be documented?
  2. fractal_tasks_core development: will there be an automated check of scope compliance
  3. custom task packages: the requirements from point 1 should be made extremely clear

(coming from discussions with @rkpasia)

Consider this task

def task_function(x: Optional[list[str]] = None) -> str:
    if x is None:
        return "A"
    elif len(x) == 0:
        return "B"
    else:
        return "C"

which has a different behavior for x=None and x=[]. I think this is a bad practice, and should be avoided.

The reason for this issue comes from fractal-analytics-platform/fractal-web#205. Depending on how we proceed in fractal-web, it's not clear whether setting x=[] will be allowed. In general, it's better to stay on the safe side and make sure that tasks are robust.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    TODO

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions