From 50aa86b28d5ed6ca0f70c9d769318208062b56c6 Mon Sep 17 00:00:00 2001 From: i2y <6240399+i2y@users.noreply.github.com> Date: Tue, 22 Sep 2026 21:59:03 +0900 Subject: [PATCH] Give Codec type variables defaults 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 Signed-off-by: i2y <6240399+i2y@users.noreply.github.com> --- pyproject.toml | 1 + src/connectrpc/_codec.py | 7 ++++--- uv.lock | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5d0ad1f7..bc03989c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ classifiers = [ dependencies = [ "protobuf-py>=0.3.0", "pyqwest>=0.5.1", + "typing_extensions>=4.13.0", ] [project.urls] diff --git a/src/connectrpc/_codec.py b/src/connectrpc/_codec.py index 73a3d928..f5df1690 100644 --- a/src/connectrpc/_codec.py +++ b/src/connectrpc/_codec.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Protocol, TypeVar +from typing import Any, Protocol from protobuf import Message, Registry from protobuf.wkt import ( @@ -18,6 +18,7 @@ type_pb, wrappers_pb, ) +from typing_extensions import TypeVar CODEC_NAME_PROTO = "proto" CODEC_NAME_JSON = "json" @@ -40,8 +41,8 @@ ) -T_contra = TypeVar("T_contra", contravariant=True) -U = TypeVar("U") +T_contra = TypeVar("T_contra", contravariant=True, default=Any) +U = TypeVar("U", default=Any) V = TypeVar("V", bound=Message) diff --git a/uv.lock b/uv.lock index 25ac7e29..40993fa5 100644 --- a/uv.lock +++ b/uv.lock @@ -158,6 +158,7 @@ source = { editable = "." } dependencies = [ { name = "protobuf-py" }, { name = "pyqwest" }, + { name = "typing-extensions" }, ] [package.dev-dependencies] @@ -203,6 +204,7 @@ docs = [ requires-dist = [ { name = "protobuf-py", specifier = ">=0.3.0" }, { name = "pyqwest", specifier = ">=0.5.1" }, + { name = "typing-extensions", specifier = ">=4.13.0" }, ] [package.metadata.requires-dev] @@ -439,7 +441,7 @@ name = "exceptiongroup" version = "1.3.1" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "typing-extensions" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/50/79/66800aadf48771f6b62f7eb014e352e5d06856655206165d775e675a02c9/exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219", size = 30371, upload-time = "2025-11-21T23:01:54.787Z" } wheels = [