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 Feb 10, 2024
1 parent 965d868 commit 55f34ca
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions src/gi-stubs/repository/Gio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ 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

ItemType = TypeVar("ItemType")

DBUS_METHOD_INVOCATION_HANDLED: bool = True
DBUS_METHOD_INVOCATION_UNHANDLED: bool = False
DEBUG_CONTROLLER_EXTENSION_POINT_NAME: str = "gio-debug-controller"
Expand Down Expand Up @@ -4035,45 +4038,64 @@ class InputVector(GObject.GPointer):
size: int = ...

# override
class ListModel(GObject.GInterface):
def __contains__(self, item: object) -> bool: ...
def __getitem__(self, position: int) -> GObject.Object: ...
def __iter__(self) -> Iterator[GObject.Object]: ...
class ListModel(GObject.GInterface, Generic[ItemType]):
# override
def __contains__(self, item: ItemType) -> bool: ...
# override
def __getitem__(self, position: int) -> ItemType: ...
# override
def __iter__(self) -> Iterator[ItemType]: ...
def __len__(self) -> int: ...
def get_item(self, position: int) -> Optional[GObject.Object]: ...
def get_item_type(self) -> Type: ...
# override
def get_item(self, position: int) -> Optional[ItemType]: ...
# override
def get_item_type(self) -> Type[ItemType]: ...
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[ItemType]):
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[ItemType]], Type[ItemType]] = ...
# override
get_n_items: Callable[[ListModel[ItemType]], int] = ...
# override
get_item: Callable[[ListModel[ItemType], int], Optional[ItemType]] = ...

class ListStore(GObject.Object, ListModel):
# override
class ListStore(GObject.Object, Generic[ItemType], ListModel[ItemType]):
class Props:
item_type: Type
# override
item_type: Type[ItemType]
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[ItemType] = ...): ...
# override
def append(self, item: ItemType) -> None: ...
# override
def find(self, item: ItemType) -> Tuple[bool, int]: ...
# override
def find_with_equal_func(
self, item: GObject.Object, equal_func: Callable[[None, None], bool]
self, item: ItemType, 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: ItemType, 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: ItemType) -> None: ...
def insert_sorted(self, item, compare_func, *user_data): ... # FIXME Function
# override
@classmethod
def new(cls, item_type: Type) -> ListStore: ...
def new(cls, item_type: Type[ItemType]) -> ListStore[ItemType]: ...
def remove(self, position: int) -> None: ...
def remove_all(self) -> None: ...
def sort(self, compare_func, *user_data): ... # FIXME Function
# override
def splice(
self, position: int, n_removals: int, additions: Sequence[GObject.Object]
self, position: int, n_removals: int, additions: Sequence[ItemType]
) -> None: ...

class ListStoreClass(GObject.GPointer):
Expand Down

0 comments on commit 55f34ca

Please sign in to comment.