[PR #6825] fix(typing): accept TypedDict state schemas under ty checker #5319

Open
opened 2026-02-20 17:51:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6825

State: open
Merged: No


Summary

This PR fixes type-checking failures reported in #6823 when using ty with TypedDict state schemas.

What changed

  • Extended StateLike to include Mapping[str, Any] so TypedDict-based state schemas satisfy stricter type checkers like ty.
  • Kept the existing protocol-based constraints (TypedDictLikeV1, TypedDictLikeV2, DataclassLike, BaseModel) intact.
  • Added a regression test for total=False TypedDict state schemas in tests/test_type_checking.py.

Why this works

ty does not consistently treat TypedDict classes as satisfying the existing protocol-only bound. Including Mapping[str, Any] in the state bound provides a compatible path for TypedDict while still rejecting unsupported schema classes.

Validation

  • uv run ruff format langgraph/_internal/_typing.py tests/test_type_checking.py --check
  • uv run ruff check langgraph/_internal/_typing.py tests/test_type_checking.py
  • uv run mypy langgraph
  • NO_DOCKER=true uv run pytest tests/test_type_checking.py
  • uv run --with ty==0.0.17 ty check /tmp/langgraph_ty_6823_check.py

AI assistance disclosure: AI support was limited to test/lint command orchestration and drafting review text. Final code changes and validation decisions were manually reviewed before submission.

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6825 **State:** open **Merged:** No --- ## Summary This PR fixes type-checking failures reported in #6823 when using `ty` with `TypedDict` state schemas. ### What changed - Extended `StateLike` to include `Mapping[str, Any]` so `TypedDict`-based state schemas satisfy stricter type checkers like `ty`. - Kept the existing protocol-based constraints (`TypedDictLikeV1`, `TypedDictLikeV2`, `DataclassLike`, `BaseModel`) intact. - Added a regression test for `total=False` TypedDict state schemas in `tests/test_type_checking.py`. ## Why this works `ty` does not consistently treat `TypedDict` classes as satisfying the existing protocol-only bound. Including `Mapping[str, Any]` in the state bound provides a compatible path for `TypedDict` while still rejecting unsupported schema classes. ## Validation - `uv run ruff format langgraph/_internal/_typing.py tests/test_type_checking.py --check` - `uv run ruff check langgraph/_internal/_typing.py tests/test_type_checking.py` - `uv run mypy langgraph` - `NO_DOCKER=true uv run pytest tests/test_type_checking.py` - `uv run --with ty==0.0.17 ty check /tmp/langgraph_ty_6823_check.py` AI assistance disclosure: AI support was limited to test/lint command orchestration and drafting review text. Final code changes and validation decisions were manually reviewed before submission.
yindo added the pull-request label 2026-02-20 17:51:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#5319