Skip to content

Give Codec type variables defaults - #345

Merged
anuraaga merged 1 commit into
mainfrom
codec-typevar-defaults
Sep 24, 2026
Merged

anuraaga merged 1 commit into
mainfrom
codec-typevar-defaults

Conversation

@i2y

@i2y i2y commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Generated *_connect.py files annotate their codecs/codec parameters with a bare Codec, which mypy --strict reports as a missing type argument ([type-arg]) in every generated service file.

Giving T_contra and U a PEP 696 default of Any, via typing_extensions.TypeVar, is enough on its own. A bare Codec then means Codec[Any, Any], and the generated code type-checks as it stands, with no change to the generator or its output. typing_extensions is now a direct dependency, with the same >=4.13.0 floor protobuf-py uses; it was already in the runtime tree through protobuf-py and pyqwest, so an install gains nothing new.

This mirrors bufbuild/protobuf-py#79.

Fixes #341

Generated *_connect.py files annotate their codecs/codec parameters with
a bare Codec, which mypy --strict reports as a missing type argument
([type-arg]) in every generated service file. Give T_contra and U a
PEP 696 default of Any via typing_extensions.TypeVar, so a bare Codec
means Codec[Any, Any] and generated code type-checks without changing
the generator or its output. typing_extensions was already in the
runtime dependency tree through protobuf-py and pyqwest; declare it
directly with the same >=4.13.0 floor protobuf-py uses. This mirrors
bufbuild/protobuf-py#79.

Fixes #341

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: i2y <6240399+i2y@users.noreply.github.com>
@i2y
i2y marked this pull request as ready for review September 22, 2026 15:20
@anuraaga
anuraaga merged commit b9ef5c3 into main Sep 24, 2026
24 checks passed
@anuraaga
anuraaga deleted the codec-typevar-defaults branch September 24, 2026 03:58
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.

generator: emit type arguments for Codec so generated code passes mypy --strict

2 participants