Skip to content

support generic TypedDict #2190

@RyanSaxe

Description

@RyanSaxe

Summary

TypeVars do not seem to be properly handled inside TypedDicts

from typing import TypedDict, reveal_type


class TestDictExample[T](TypedDict):
    id: int
    name: str
    active: bool
    bug: T


class Example[T]:
    def __init__(self, data: TestDictExample[T]) -> None:
        self.attr: TestDictExample[T] = data

    def do_something(self) -> T:
        value = self.attr["bug"] # ty thinks this is Unknown instead of T
        name = self.attr["name"] # ty correctly gets this as str
        return value

https://play.ty.dev/fa58789a-4d72-4f76-802d-7dafe74e52b8

Version

ty 0.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    genericsBugs or features relating to ty's generics implementationtypeddict

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions