fix: use TypeAlias for Python 3.11 compatibility in streamable HTTP demo#197
Merged
fix: use TypeAlias for Python 3.11 compatibility in streamable HTTP demo#197
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
demo/streamable_http_client.pyscript declaredrequires-python = ">=3.11"in its inlineuv run --scriptmetadata but usedtype ScenarioStep = tuple[str, str], the PEP 695 type alias syntax introduced in Python 3.12.SyntaxErrorbefore the demo workflow starts, even though the metadata promises 3.11 support.typing.TypeAliasannotation form (ScenarioStep: TypeAlias = tuple[str, str]) and addfrom typing import TypeAliasimport, preserving the>=3.11floor.test_demo_python_floor_matches_syntaxtotests/test_streamable_http_demo.py: reads the inline metadata floor and asserts no PEP 695typestatements 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 passeduv run --python 3.11 --extra dev pytest tests/test_streamable_http_demo.py -v→ 3 passeduv run --extra dev pytest tests/ -q→ all tests passgrep 'type ScenarioStep' demo/streamable_http_client.py→ no matchgrep 'TypeAlias' demo/streamable_http_client.py→ import on line 21, annotation on line 27