Skip to content

fix: use TypeAlias for Python 3.11 compatibility in streamable HTTP demo#197

Merged
imaurer merged 2 commits intomainfrom
fix-streamable-http-python-version
Mar 11, 2026
Merged

fix: use TypeAlias for Python 3.11 compatibility in streamable HTTP demo#197
imaurer merged 2 commits intomainfrom
fix-streamable-http-python-version

Conversation

@imaurer
Copy link
Collaborator

@imaurer imaurer commented Mar 11, 2026

Summary

  • The demo/streamable_http_client.py script declared requires-python = ">=3.11" in its inline uv run --script metadata but used type ScenarioStep = tuple[str, str], the PEP 695 type alias syntax introduced in Python 3.12.
  • A user on Python 3.11 would encounter a SyntaxError before the demo workflow starts, even though the metadata promises 3.11 support.
  • Replace the PEP 695 statement with the typing.TypeAlias annotation form (ScenarioStep: TypeAlias = tuple[str, str]) and add from typing import TypeAlias import, preserving the >=3.11 floor.
  • Add test_demo_python_floor_matches_syntax to tests/test_streamable_http_demo.py: reads the inline metadata floor and asserts no PEP 695 type statements are present when that floor is below 3.12, preventing silent drift in future edits.

Test plan

  • uv run --extra dev pytest tests/test_streamable_http_demo.py -v → 3 passed
  • uv run --python 3.11 --extra dev pytest tests/test_streamable_http_demo.py -v → 3 passed
  • uv run --extra dev pytest tests/ -q → all tests pass
  • grep 'type ScenarioStep' demo/streamable_http_client.py → no match
  • grep 'TypeAlias' demo/streamable_http_client.py → import on line 21, annotation on line 27

imaurer added 2 commits March 11, 2026 17:08
… compatibility

The streamable HTTP demo script advertised requires-python = ">=3.11" but used
the `type ScenarioStep = ...` syntax introduced in Python 3.12 (PEP 695). Replace
with `ScenarioStep: TypeAlias = tuple[str, str]` and add the `from typing import
TypeAlias` import so the script parses under the declared Python floor.

Add a regression test that reads the inline metadata floor and asserts no PEP 695
`type` statements are present when the floor is below 3.12.
@imaurer imaurer closed this Mar 11, 2026
@imaurer imaurer reopened this Mar 11, 2026
@imaurer imaurer merged commit bc8fef2 into main Mar 11, 2026
4 checks passed
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