Skip to content

Commit b96cc91

Browse files
committed
typing: Gio: Make ListModel and ListStore generic
1 parent 0c4e4a7 commit b96cc91

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

src/gi-stubs/repository/Gio.pyi

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from typing import Optional
44
from typing import Sequence
55
from typing import Tuple
66
from typing import Type
7+
from typing import TypeVar
78

89
from gi.repository import GLib
910
from gi.repository import GObject
@@ -4032,41 +4033,60 @@ class InputVector(GObject.GPointer):
40324033
buffer: None = ...
40334034
size: int = ...
40344035

4035-
class ListModel(GObject.Object):
4036-
def get_item(self, position: int) -> Optional[GObject.Object]: ...
4037-
def get_item_type(self) -> Type: ...
4036+
T = TypeVar('T')
4037+
4038+
# override
4039+
class ListModel(GObject.Object, Generic[T]):
4040+
# override
4041+
def get_item(self, position: int) -> Optional[T]: ...
4042+
# override
4043+
def get_item_type(self) -> Type[T]: ...
40384044
def get_n_items(self) -> int: ...
40394045
def items_changed(self, position: int, removed: int, added: int) -> None: ...
40404046

4041-
class ListModelInterface(GObject.GPointer):
4047+
# override
4048+
class ListModelInterface(GObject.GPointer, Generic[T]):
40424049
g_iface: GObject.TypeInterface = ...
4043-
get_item_type: Callable[[ListModel], Type] = ...
4044-
get_n_items: Callable[[ListModel], int] = ...
4045-
get_item: Callable[[ListModel, int], Optional[GObject.Object]] = ...
4050+
# override
4051+
get_item_type: Callable[[ListModel[T]], Type[T]] = ...
4052+
# override
4053+
get_n_items: Callable[[ListModel[T]], int] = ...
4054+
# override
4055+
get_item: Callable[[ListModel[T], int], Optional[T]] = ...
40464056

4047-
class ListStore(GObject.Object, ListModel):
4057+
# override
4058+
class ListStore(GObject.Object, Generic[T], ListModel[T]):
40484059
class Props:
4049-
item_type: Type
4060+
# override
4061+
item_type: Type[T]
40504062
n_items: int
40514063
props: Props = ...
4052-
def __init__(self, item_type: Type = ...): ...
4053-
def append(self, item: GObject.Object) -> None: ...
4054-
def find(self, item: GObject.Object) -> Tuple[bool, int]: ...
4064+
# override
4065+
def __init__(self, item_type: Type[T] = ...): ...
4066+
# override
4067+
def append(self, item: T) -> None: ...
4068+
# override
4069+
def find(self, item: T) -> Tuple[bool, int]: ...
4070+
# override
40554071
def find_with_equal_func(
4056-
self, item: GObject.Object, equal_func: Callable[[None, None], bool]
4072+
self, item: T, equal_func: Callable[[None, None], bool]
40574073
) -> Tuple[bool, int]: ...
4074+
# override
40584075
def find_with_equal_func_full(
4059-
self, item: GObject.Object, equal_func: Callable[..., bool], *user_data: Any
4076+
self, item: T, equal_func: Callable[..., bool], *user_data: Any
40604077
) -> Tuple[bool, int]: ...
4061-
def insert(self, position: int, item: GObject.Object) -> None: ...
4078+
# override
4079+
def insert(self, position: int, item: T) -> None: ...
40624080
def insert_sorted(self, *args, **kwargs): ... # FIXME Method
4081+
# override
40634082
@classmethod
4064-
def new(cls, item_type: Type) -> ListStore: ...
4083+
def new(cls, item_type: Type[T]) -> ListStore[T]: ...
40654084
def remove(self, position: int) -> None: ...
40664085
def remove_all(self) -> None: ...
40674086
def sort(self, *args, **kwargs): ... # FIXME Method
4087+
# override
40684088
def splice(
4069-
self, position: int, n_removals: int, additions: Sequence[GObject.Object]
4089+
self, position: int, n_removals: int, additions: Sequence[T]
40704090
) -> None: ...
40714091

40724092
class ListStoreClass(GObject.GPointer):

0 commit comments

Comments
 (0)