Skip to content

Generics #419

Description

@sharkdp

Basilisk doesn't seem to handle rather basic examples involving generics, for example:

from typing import assert_type

class P: ...

def duplicate[T](value: T) -> tuple[T, T]:
    return value, value

assert_type(duplicate(P()), tuple[P, P])

Basilisk fails this assertion and incorrectly infers tuple[T, T] (leaking type variables) instead of tuple[P, P].

Using list[T] or int | T in the return type leads to similar failures.

It also seems to rely on the fact that type variables are capitalized? It fails this assertion and infers t instead of int:

def identity[t](value: t) -> t:
    return value

assert_type(identity(1), int)

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