Skip to content

[types] incomptabile assignment types due to invariant and type union #90

Description

@rchui

Instead of using type unions (like used here https://github.com/typesense/typesense-python/blob/master/src/typesense/types/collection.py#L226-L232), the library should use bound typevar like:

a: list[int | str]
b: list[int] = [1]

a = b  # failure: incompatible assignment due to invariant

from typing import TypeVar

ListT = TypeVar("ListT", bound=int | str)

c: list[ListT]
d: list[int] = [1]
e: list[str] = ["a"]
f: list[int | str] = [1, "a"]

c = d  # success
c = e  # success
c = f  # success

The type checkers are really unhappy with the way that the types are currently formulated. I should be able to supply a list of just RegularCollectionFieldSchema to CollectionUpdateSchema. Instead it errors due to the type construction. I shouldn't have to reverse engineer the internal union type to satisfy the type checker.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions