Skip to content

feat(http-client-python): export TypedDicts from namespace-root __init__.py#7

Closed
l0lawrence wants to merge 1 commit into
mainfrom
l0lawrence-bookish-invention
Closed

feat(http-client-python): export TypedDicts from namespace-root __init__.py#7
l0lawrence wants to merge 1 commit into
mainfrom
l0lawrence-bookish-invention

Conversation

@l0lawrence

Copy link
Copy Markdown
Owner

Problem

In dpg and typeddict models modes, generated TypedDicts (and their Union/Literal aliases) are written to types.py, but they were never re-exported from the namespace-root __init__.py — only clients and __version__ were. As a result, from <package> import MyModel did not work; the TypedDicts were only reachable via the implicit types submodule (from <package> import types; types.MyModel).

Change

  • general_serializer.py — added typeddict_names_for_init(), which mirrors the exact gate and name-selection used to generate types.py (literal_enums + discriminated_base_models + typeddict_models via TypesSerializer) so only names that actually exist in types.py are imported. Returns [] for the async (aio/) init since types.py lives at the namespace root. serialize_init_file now feeds these names to the template.
  • init.py.jinja2 — emits from .types import (...) and adds the names to __all__ when present.

This covers both DPG mode (TypedDict copies of input models, base="typeddict") and typeddict mode (all models as TypedDicts).

Result

from my_package import MyModel  # previously only reachable via `from my_package import types`

Tests

Added 4 unit tests in test_typeddict.py:

  • typeddict-mode init re-exports TypedDicts
  • dpg-mode init re-exports TypedDict copies
  • async (aio/) init does not import from .types
  • no-types case emits no .types import

Validation

  • New + existing typeddict tests: 17 passed
  • black formatted, pylint 10.00/10
  • The 3 unrelated tests/unit failures (XML/model_base serialization) are pre-existing and reproduce on a clean checkout
  • Generated SDK output is not git-tracked, so no regeneration is required
  • Added a feature chronus changelog entry

…t__.py

In dpg and typeddict models modes, generated TypedDicts (and their Union/Literal aliases) live in types.py but were never re-exported from the namespace-root __init__.py. Import them from .types and add to __all__ so they can be imported directly from the package.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - feature ✏️

Export generated TypedDict types (and their Union/Literal aliases from types.py) from the namespace-root __init__.py in dpg and typeddict models modes, so they can be imported directly from the package:,> ,> python,> from my_package import MyModel # previously only reachable via `from my_package import types`,>

@l0lawrence

Copy link
Copy Markdown
Owner Author

Retargeting to microsoft/typespec:main.

@l0lawrence l0lawrence closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant