Skip to content

objects that take list should use a covariant type like Sequence instead

if i pass a list of jobs to the needs argument in Job's constructor, i get the following error from my type checker (pyright):

def get_jobs() -> list[Job]: ...


jobs: list[Job] = get_jobs()

job = Job(needs=jobs, script="asdf") # error
Argument of type "list[Job]" cannot be assigned to parameter "needs" of type "List[Need | Job | Sequence] | None" in function "__init__"
  Type "list[Job]" is not assignable to type "List[Need | Job | Sequence] | None"
    "list[Job]" is not assignable to "List[Need | Job | Sequence]"
      Type parameter "_T@list" is invariant, but "Job" is not the same as "Need | Job | Sequence"
      Consider switching from "list" to "Sequence" which is covariant
    "list[Job]" is not assignable to "None"

if needs was a typing.Sequence instead of a List, this error would go away. it should use Sequence instead because the class does not mutate the list

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information