Skip to content

Key access on a subclass of a specialized generic TypedDict fails with Unsupported type ~T #7997

Backlog

Description

@FarhanAliRaza

Problem

#7887 made key access work on a parametrized generic TypedDict (p: P[int]). A subclass of a specialized generic TypedDict still fails at compile time:

TypeError: Unsupported type ~T for guess_type.

get_attribute_access_type (utils/types.py) handles the class as a bare class and reads its annotations with get_type_hints. The annotations of a subclass of P[str] still contain the unbound T, so the var type becomes ~T. get_typed_dict_field_types(R) already resolves the field correctly to {'value': str}, but the bare-class branch does not use it.

Repro

from typing import Generic, TypedDict, TypeVar

import reflex as rx

T = TypeVar("T")


class P(TypedDict, Generic[T]):
    value: T


class R(P[str]):
    pass


class State(rx.State):
    r: R = {"value": "a"}


State.r["value"]  # TypeError: Unsupported type ~T for guess_type.

Checked on main at 1e4eb60, Python 3.14.6.

Expected

State.r["value"] is typed str, as State.p["value"] is for p: P[str].

Fix direction

In get_attribute_access_type, resolve the field type of every TypedDict, bare class or alias, through get_typed_dict_field_types. That helper has no cache, and a bare-class lookup with it takes about 12 µs instead of about 0.6 µs (measured during the #7887 review). So add a cache to the helper, or use it only when get_type_hints returns a TypeVar.

The comment at utils/types.py:1115 (_get_column_access_type) still says that the keys of a parametrized generic TypedDict "are not resolved". That is not true after #7887. Update the comment in the same change.

Activity

  1. added
    bug
    on Nov 25, 2026
  2. linear-code commented on Nov 25, 2026

    @linear-code
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions