From c1b694430268c5e6e55cf2caa4c09c122f4c3ad7 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 11 Jun 2026 01:00:36 +0200 Subject: [PATCH 1/2] fix type hint for GPUPromise --- wgpu/_classes.py | 4 ++-- wgpu/backends/wgpu_native/_api.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wgpu/_classes.py b/wgpu/_classes.py index c1e6a502..d10edaeb 100644 --- a/wgpu/_classes.py +++ b/wgpu/_classes.py @@ -15,7 +15,7 @@ import itertools from typing import Sequence -from ._async import GPUPromise as BaseGPUPromise +from ._async import GPUPromise as BaseGPUPromise, AwaitedType from ._coreutils import ApiDiff, str_flag_to_int, ArrayLike, CanvasLike from ._diagnostics import diagnostics, texture_format_to_bpp from . import flags, enums, structs @@ -224,7 +224,7 @@ def get_canvas_context(self, present_info: dict) -> GPUCanvasContext: @apidiff.add("Added for async support") -class GPUPromise(BaseGPUPromise): +class GPUPromise(BaseGPUPromise[AwaitedType]): pass diff --git a/wgpu/backends/wgpu_native/_api.py b/wgpu/backends/wgpu_native/_api.py index c96ff973..ea99c39b 100644 --- a/wgpu/backends/wgpu_native/_api.py +++ b/wgpu/backends/wgpu_native/_api.py @@ -24,6 +24,7 @@ from typing import NoReturn, Sequence from ..._coreutils import str_flag_to_int, ArrayLike, CanvasLike +from ..._async import AwaitedType from ... import classes, flags, enums, structs from ._ffi import ffi, lib @@ -684,7 +685,7 @@ def get_canvas_context(self, present_info: dict) -> GPUCanvasContext: gpu = GPU() -class GPUPromise(classes.GPUPromise): +class GPUPromise(classes.GPUPromise[AwaitedType]): def _sync_wait(self): # In the wgpu-native backend, we do the polling in a per-device thread. # The base class already sets a threading.Event, we can just use that here. From e4796d386bd2693e4ee7d30e526b1fc07ff229a9 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 11 Jun 2026 01:00:45 +0200 Subject: [PATCH 2/2] edge case for codegen --- codegen/apipatcher.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codegen/apipatcher.py b/codegen/apipatcher.py index f7303f7a..80371f20 100644 --- a/codegen/apipatcher.py +++ b/codegen/apipatcher.py @@ -624,6 +624,10 @@ def class_is_known(self, classname): def get_class_def(self, classname): line, _ = self.classes[classname] + if line.startswith("class GPUPromise"): + # otherwise the else block below strips the typevar. + return "class GPUPromise(classes.GPUPromise[AwaitedType]):" + if "):" not in line: return line.replace(":", f"(classes.{classname}):") else: