Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing: Gio: Make ListModel and ListStore generic #115

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think thats necessary, if the class itself has a "override" annotation, then it will be completely ignored by the generator. So no need to add override to each method.

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
Loading