Skip to content

Commit 700efac

Browse files
authored
Make GPUAdapterInfo inherit from dict (#709)
1 parent 5ddb038 commit 700efac

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ Possible sections in each release:
1717
* Security: in case of vulnerabilities.
1818

1919

20+
### [v0.22.1] - 17-04-2025
21+
22+
Changed:
23+
24+
* Make ``GPUAdapterInfo`` a subclass of dict. Since ``adapter.info`` returned a dict before 0.22.0, this makes it compatible again, with code that expects a dict.
25+
26+
2027
### [v0.22.0] - 16-04-2025
2128

2229
Added:
@@ -26,8 +33,8 @@ Added:
2633

2734
Changed:
2835

29-
* Make ``adapter.info`` return GPUAdapterInfo by @fyellin in https://github.com/pygfx/wgpu-py/pull/699
30-
* Give AdapterInfo a repr by @almarklein in https://github.com/pygfx/wgpu-py/pull/707
36+
* Make ``adapter.info`` return ``GPUAdapterInfo`` by @fyellin in https://github.com/pygfx/wgpu-py/pull/699
37+
* Give ``GPUAdapterInfo`` a repr by @almarklein in https://github.com/pygfx/wgpu-py/pull/707
3138

3239
Fixed:
3340

codegen/apipatcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ def get_class_def(self, classname):
404404
bases.append("MemoryError")
405405
elif not bases:
406406
bases.append("Exception")
407+
elif classname in ["GPUAdapterInfo"]:
408+
bases.append("dict")
407409

408410
bases = "" if not bases else f"({', '.join(bases)})"
409411
return f"class {classname}{bases}:"

wgpu/_classes.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,54 +549,48 @@ def _release(self):
549549
self._drop_texture()
550550

551551

552-
class GPUAdapterInfo:
552+
class GPUAdapterInfo(dict):
553553
"""Represents information about an adapter."""
554554

555-
def __init__(self, info):
556-
self._info = info
557-
558555
def __repr__(self):
559-
parts = [f"{k}={v!r}" for k, v in self._info.items()]
560-
return f"<GPUAdapterInfo with {', '.join(parts)}>"
556+
parts = [f"{k}={v!r}" for k, v in self.items()]
557+
return f"<GPUAdapterInfo dict with {', '.join(parts)}>"
561558

562559
# IDL: readonly attribute DOMString vendor;
563560
@property
564561
def vendor(self):
565562
"""The vendor that built this adaptor."""
566-
return self._info["vendor"]
563+
return self["vendor"]
567564

568565
# IDL: readonly attribute DOMString architecture;
569566
@property
570567
def architecture(self):
571568
"""The adapters architecrure."""
572-
return self._info["architecture"]
569+
return self["architecture"]
573570

574571
# IDL: readonly attribute DOMString device;
575572
@property
576573
def device(self):
577574
"""The kind of device that this adapter represents."""
578-
return self._info["device"]
575+
return self["device"]
579576

580577
# IDL: readonly attribute DOMString description;
581578
@property
582579
def description(self):
583580
"""A textual description of the adapter."""
584-
return self._info["description"]
581+
return self["description"]
585582

586583
# IDL: readonly attribute unsigned long subgroupMinSize;
587584
@property
588585
def subgroup_min_size(self):
589586
"""If the "subgroups" feature is supported, the minimum supported subgroup size for the adapter."""
590-
return self._info.get("subgroup_min_size")
587+
return self.get("subgroup_min_size")
591588

592589
# IDL: readonly attribute unsigned long subgroupMaxSize;
593590
@property
594591
def subgroup_max_size(self):
595592
"""If the "subgroups" feature is supported, the maximum supported subgroup size for the adapter."""
596-
return self._info.get("subgroup_max_size")
597-
598-
def __getitem__(self, item):
599-
return self._info.get(item, None)
593+
return self.get("subgroup_max_size")
600594

601595

602596
class GPUAdapter:

wgpu/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# This is the reference version number, to be bumped before each release.
1212
# The build system detects this definition when building a distribution.
13-
__version__ = "0.22.0"
13+
__version__ = "0.22.1"
1414

1515
# Allow using nearly the same code in different projects
1616
project_name = "wgpu"

wgpu/resources/codegen_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Diffs for GPUTextureView: add size, add texture
1919
* Diffs for GPUBindingCommandsMixin: change set_bind_group
2020
* Diffs for GPUQueue: add read_buffer, add read_texture, hide copy_external_image_to_texture
21-
* Validated 37 classes, 124 methods, 49 properties
21+
* Validated 37 classes, 122 methods, 49 properties
2222
### Patching API for backends/wgpu_native/_api.py
2323
* Validated 37 classes, 124 methods, 0 properties
2424
## Validating backends/wgpu_native/_api.py

0 commit comments

Comments
 (0)