Skip to content

Commit

Permalink
typing: Gio: Make ListModel and ListStore generic
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Mar 9, 2023
1 parent 0c4e4a7 commit b96cc91
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/gi-stubs/repository/Gio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from typing import Optional
from typing import Sequence
from typing import Tuple
from typing import Type
from typing import TypeVar

from gi.repository import GLib
from gi.repository import GObject
Expand Down Expand Up @@ -4032,41 +4033,60 @@ class InputVector(GObject.GPointer):
buffer: None = ...
size: int = ...

class ListModel(GObject.Object):
def get_item(self, position: int) -> Optional[GObject.Object]: ...
def get_item_type(self) -> Type: ...
T = TypeVar('T')

# override
class ListModel(GObject.Object, Generic[T]):
# override
def get_item(self, position: int) -> Optional[T]: ...
# override
def get_item_type(self) -> Type[T]: ...
def get_n_items(self) -> int: ...
def items_changed(self, position: int, removed: int, added: int) -> None: ...

class ListModelInterface(GObject.GPointer):
# override
class ListModelInterface(GObject.GPointer, Generic[T]):
g_iface: GObject.TypeInterface = ...
get_item_type: Callable[[ListModel], Type] = ...
get_n_items: Callable[[ListModel], int] = ...
get_item: Callable[[ListModel, int], Optional[GObject.Object]] = ...
# override
get_item_type: Callable[[ListModel[T]], Type[T]] = ...
# override
get_n_items: Callable[[ListModel[T]], int] = ...
# override
get_item: Callable[[ListModel[T], int], Optional[T]] = ...

class ListStore(GObject.Object, ListModel):
# override
class ListStore(GObject.Object, Generic[T], ListModel[T]):
class Props:
item_type: Type
# override
item_type: Type[T]
n_items: int
props: Props = ...
def __init__(self, item_type: Type = ...): ...
def append(self, item: GObject.Object) -> None: ...
def find(self, item: GObject.Object) -> Tuple[bool, int]: ...
# override
def __init__(self, item_type: Type[T] = ...): ...
# override
def append(self, item: T) -> None: ...
# override
def find(self, item: T) -> Tuple[bool, int]: ...
# override
def find_with_equal_func(
self, item: GObject.Object, equal_func: Callable[[None, None], bool]
self, item: T, equal_func: Callable[[None, None], bool]
) -> Tuple[bool, int]: ...
# override
def find_with_equal_func_full(
self, item: GObject.Object, equal_func: Callable[..., bool], *user_data: Any
self, item: T, equal_func: Callable[..., bool], *user_data: Any
) -> Tuple[bool, int]: ...
def insert(self, position: int, item: GObject.Object) -> None: ...
# override
def insert(self, position: int, item: T) -> None: ...
def insert_sorted(self, *args, **kwargs): ... # FIXME Method
# override
@classmethod
def new(cls, item_type: Type) -> ListStore: ...
def new(cls, item_type: Type[T]) -> ListStore[T]: ...
def remove(self, position: int) -> None: ...
def remove_all(self) -> None: ...
def sort(self, *args, **kwargs): ... # FIXME Method
# override
def splice(
self, position: int, n_removals: int, additions: Sequence[GObject.Object]
self, position: int, n_removals: int, additions: Sequence[T]
) -> None: ...

class ListStoreClass(GObject.GPointer):
Expand Down

0 comments on commit b96cc91

Please sign in to comment.