Skip to content

improve typevar solving #623

@DetachHead

Description

@DetachHead

Summary

def safe[T](value: T | None) -> T: ...


def _(value: int | None):
    reveal_type(safe(value)) # int | None

https://play.ty.dev/8370e070-c8b0-430a-8e42-b645793e5561

it looks like T is being inferred as int | None, but it would be more convenient if it was inferred as int, so that the safe function can behave sort of like a type guard that removes None from types.

both pyright and mypy support inferring the generics this way.

Version

0.0.1-alpha.8 (c1337c9 2025-06-02)

Sub-issues

Metadata

Metadata

Assignees

Labels

genericsBugs or features relating to ty's generics implementation

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions