summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2023-03-10 00:18:00 +0100
committerJan Tojnar <jtojnar@gmail.com>2023-03-10 00:22:57 +0100
commit17758e5f1ceb9506dfc10d364f8aeb395c31bc2f (patch)
tree964babb646f64660c35b664fcd811fb24c148cf0
parent61ef471f5759b1ef676e5273318e7fdb282d7a75 (diff)
downloadpygobject-17758e5f1ceb9506dfc10d364f8aeb395c31bc2f.tar.gz
overrides/Gio/ListStore: Inherit Generic
Otherwise trying to use `Gio.ListStore[Foo]` in a type annotation in an app will crash: TypeError: 'GObjectMeta' object is not subscriptable
-rw-r--r--gi/overrides/Gio.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py
index c807fe0b..09c7d441 100644
--- a/gi/overrides/Gio.py
+++ b/gi/overrides/Gio.py
@@ -26,6 +26,9 @@ from ..module import get_introspection_module
from gi import PyGIWarning
from gi.repository import GLib
+from gi.repository import GObject
+
+from typing import Generic, TypeVar
import sys
@@ -421,7 +424,10 @@ DBusProxy = override(DBusProxy)
__all__.append('DBusProxy')
-class ListModel(Gio.ListModel):
+ObjectItemType = TypeVar('ObjectItemType', bound=GObject.Object)
+
+
+class ListModel(Gio.ListModel, Generic[ObjectItemType]):
def __getitem__(self, key):
if isinstance(key, slice):
@@ -473,7 +479,7 @@ else:
self.splice(position, n_removals, additions)
-class ListStore(Gio.ListStore):
+class ListStore(Gio.ListStore, Generic[ObjectItemType]):
def sort(self, compare_func, *user_data):
compare_func = wrap_list_store_sort_func(compare_func)