Skip to content

mypy override errors for input/output/requires #522

@hirosassa

Description

@hirosassa

Problem

Luigi master added type annotations to Task.input(), Task.output(), and Task.requires(). This causes mypy to report [override] errors in TaskOnKart:

gokart/task.py: error: Return type "FlattenableItems[TargetOnKart]" of "input" incompatible with return type "Target | list[Target] | dict[str, Target]" in supertype "Task"  [override]
gokart/task.py: error: Return type "FlattenableItems[TargetOnKart]" of "output" incompatible with return type "Target | list[Target] | dict[str, Target]" in supertype "Task"  [override]
gokart/task.py: error: Return type "FlattenableItems[TaskOnKart[Any]]" of "requires" incompatible with return type "Task | list[Task] | dict[str, Task]" in supertype "Task"  [override]

Root Cause

Luigi defines return types as T | list[T] | dict[str, T], while gokart uses FlattenableItems[T]:

FlattenableItems: TypeAlias = T | list['FlattenableItems[T]'] | tuple['FlattenableItems[T]', ...] | dict[str, 'FlattenableItems[T]']

Two differences make FlattenableItems[T] incompatible as a subtype of luigi's type:

  1. Includes tuple — not present in luigi's type
  2. Recursively nested — e.g. list[list[T]] is valid, but luigi only allows list[T]

The concrete type parameters (TargetOnKart <: Target, TaskOnKart <: Task) are fine (covariant direction).

Options

  1. Suppress with # type: ignore[override] — simplest; no runtime issue exists
  2. Narrow FlattenableItems to match luigi — would need to audit all usages for tuple/nested patterns
  3. Propose widening luigi's return types — upstream PR to support tuple and recursive nesting
  4. Combination: suppress now, propose upstream change later

Discussion

Which approach should we take?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions