From 47b2e7196eb314cf31c3b451412259dc512732ac Mon Sep 17 00:00:00 2001 From: Reinis Taukulis Date: Wed, 30 Nov 2022 22:29:15 +0200 Subject: [PATCH] [i3] Use generic self type variable to avoid type check errors https://github.com/altdesktop/i3ipc-python/issues/190 --- i3/i3init/typings.patch | 182 ++++++++++++++++++++++++++++++-- i3/i3init/typings/i3ipc/con.pyi | 38 +++---- 2 files changed, 193 insertions(+), 27 deletions(-) diff --git a/i3/i3init/typings.patch b/i3/i3init/typings.patch index ce5b5421..e1173841 100644 --- a/i3/i3init/typings.patch +++ b/i3/i3init/typings.patch @@ -1,6 +1,6 @@ diff -ruN typings/i3ipc/aio/__init__.pyi typings.patched/i3ipc/aio/__init__.pyi ---- typings/i3ipc/aio/__init__.pyi 2022-11-30 21:30:26.454203922 +0200 -+++ typings.patched/i3ipc/aio/__init__.pyi 2022-11-30 21:30:25.458199758 +0200 +--- typings/i3ipc/aio/__init__.pyi 2022-11-30 22:29:39.738894713 +0200 ++++ typings.patched/i3ipc/aio/__init__.pyi 2022-11-30 22:29:38.730890954 +0200 @@ -3,3 +3,5 @@ """ @@ -8,9 +8,23 @@ diff -ruN typings/i3ipc/aio/__init__.pyi typings.patched/i3ipc/aio/__init__.pyi + +__all__ = ["Con", "Connection"] diff -ruN typings/i3ipc/con.pyi typings.patched/i3ipc/con.pyi ---- typings/i3ipc/con.pyi 2022-11-30 21:30:26.474204005 +0200 -+++ typings.patched/i3ipc/con.pyi 2022-11-30 21:30:25.458199758 +0200 -@@ -86,6 +86,11 @@ +--- typings/i3ipc/con.pyi 2022-11-30 22:29:39.766894818 +0200 ++++ typings.patched/i3ipc/con.pyi 2022-11-30 22:29:38.730890954 +0200 +@@ -2,10 +2,12 @@ + This type stub file was generated by pyright. + """ + +-from typing import List, Optional ++from typing import List, Optional, TypeVar + + from . import replies + ++TCon = TypeVar("TCon", bound="Con") ++ + class Con: + """A container of a window and child containers gotten from :func:`i3ipc.Connection.get_tree()` or events. + +@@ -86,6 +88,11 @@ :vartype ipc_data: dict """ @@ -22,9 +36,159 @@ diff -ruN typings/i3ipc/con.pyi typings.patched/i3ipc/con.pyi def __init__(self, data, parent, conn) -> None: ... def __iter__(self): # -> Generator[Unknown, None, None]: """Iterate through the descendents of this node (breadth-first tree traversal)""" +@@ -97,14 +104,14 @@ + :rtype: bool + """ + ... +- def root(self) -> Con: ++ def root(self: TCon) -> TCon: + """Gets the root container. + + :returns: The root container. + :rtype: :class:`Con` + """ + ... +- def descendants(self) -> List[Con]: ++ def descendants(self: TCon) -> List[TCon]: + """Gets a list of all child containers for the container in + breadth-first order. + +@@ -112,7 +119,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def descendents(self) -> List[Con]: ++ def descendents(self: TCon) -> List[TCon]: + """Gets a list of all child containers for the container in + breadth-first order. + +@@ -123,7 +130,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def leaves(self) -> List[Con]: ++ def leaves(self: TCon) -> List[TCon]: + """Gets a list of leaf child containers for this container in + breadth-first order. Leaf containers normally contain application + windows. +@@ -152,14 +159,14 @@ + :rtype: list(:class:`CommandReply `) + """ + ... +- def workspaces(self) -> List[Con]: ++ def workspaces(self: TCon) -> List[TCon]: + """Gets a list of workspace containers for this tree. + + :returns: A list of workspace containers. + :rtype: list(:class:`Con`) + """ + ... +- def find_focused(self) -> Optional[Con]: ++ def find_focused(self: TCon) -> Optional[TCon]: + """Finds the focused container under this container if it exists. + + :returns: The focused container if it exists. +@@ -167,7 +174,7 @@ + under this container + """ + ... +- def find_by_id(self, id: int) -> Optional[Con]: ++ def find_by_id(self: TCon, id: int) -> Optional[TCon]: + """Finds a container with the given container id under this node. + + :returns: The container with this container id if it exists. +@@ -175,14 +182,14 @@ + this container id. + """ + ... +- def find_by_pid(self, pid: int) -> List[Con]: ++ def find_by_pid(self: TCon, pid: int) -> List[TCon]: + """Finds all the containers under this node with this pid. + + :returns: A list of containers with this pid. + :rtype: list(:class:`Con`) + """ + ... +- def find_by_window(self, window: int) -> Optional[Con]: ++ def find_by_window(self: TCon, window: int) -> Optional[TCon]: + """Finds a container with the given window id under this node. + + :returns: The container with this window id if it exists. +@@ -190,7 +197,7 @@ + this window id. + """ + ... +- def find_by_role(self, pattern: str) -> List[Con]: ++ def find_by_role(self: TCon, pattern: str) -> List[TCon]: + """Finds all the containers under this node with a window role that + matches the given regex pattern. + +@@ -199,7 +206,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def find_named(self, pattern: str) -> List[Con]: ++ def find_named(self: TCon, pattern: str) -> List[TCon]: + """Finds all the containers under this node with a name that + matches the given regex pattern. + +@@ -208,7 +215,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def find_titled(self, pattern: str) -> List[Con]: ++ def find_titled(self: TCon, pattern: str) -> List[TCon]: + """Finds all the containers under this node with a window title that + matches the given regex pattern. + +@@ -217,7 +224,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def find_classed(self, pattern: str) -> List[Con]: ++ def find_classed(self: TCon, pattern: str) -> List[TCon]: + """Finds all the containers under this node with a window class, + or app_id that matches the given regex pattern. + +@@ -226,7 +233,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def find_instanced(self, pattern: str) -> List[Con]: ++ def find_instanced(self: TCon, pattern: str) -> List[TCon]: + """Finds all the containers under this node with a window instance that + matches the given regex pattern. + +@@ -235,7 +242,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def find_marked(self, pattern: str = ...) -> List[Con]: ++ def find_marked(self: TCon, pattern: str = ...) -> List[TCon]: + """Finds all the containers under this node with a mark that + matches the given regex pattern. + +@@ -244,7 +251,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def find_fullscreen(self) -> List[Con]: ++ def find_fullscreen(self: TCon) -> List[TCon]: + """Finds all the containers under this node that are in fullscreen + mode. + +@@ -252,7 +259,7 @@ + :rtype: list(:class:`Con`) + """ + ... +- def workspace(self) -> Optional[Con]: ++ def workspace(self: TCon) -> Optional[TCon]: + """Finds the workspace container for this node if this container is at + or below the workspace level. + diff -ruN typings/i3ipc/events.pyi typings.patched/i3ipc/events.pyi ---- typings/i3ipc/events.pyi 2022-11-30 21:30:26.478204021 +0200 -+++ typings.patched/i3ipc/events.pyi 2022-11-30 21:30:25.458199758 +0200 +--- typings/i3ipc/events.pyi 2022-11-30 22:29:39.762894800 +0200 ++++ typings.patched/i3ipc/events.pyi 2022-11-30 22:29:38.730890954 +0200 @@ -4,6 +4,7 @@ from enum import Enum @@ -42,8 +206,8 @@ diff -ruN typings/i3ipc/events.pyi typings.patched/i3ipc/events.pyi class BarconfigUpdateEvent(IpcBaseEvent, BarConfigReply): diff -ruN typings/i3ipc/__init__.pyi typings.patched/i3ipc/__init__.pyi ---- typings/i3ipc/__init__.pyi 2022-11-30 21:30:26.462203956 +0200 -+++ typings.patched/i3ipc/__init__.pyi 2022-11-30 21:30:25.458199758 +0200 +--- typings/i3ipc/__init__.pyi 2022-11-30 22:29:39.742894727 +0200 ++++ typings.patched/i3ipc/__init__.pyi 2022-11-30 22:29:38.730890954 +0200 @@ -2,16 +2,6 @@ This type stub file was generated by pyright. """ diff --git a/i3/i3init/typings/i3ipc/con.pyi b/i3/i3init/typings/i3ipc/con.pyi index 6a03d2fc..ab499354 100644 --- a/i3/i3init/typings/i3ipc/con.pyi +++ b/i3/i3init/typings/i3ipc/con.pyi @@ -2,10 +2,12 @@ This type stub file was generated by pyright. """ -from typing import List, Optional +from typing import List, Optional, TypeVar from . import replies +TCon = TypeVar("TCon", bound="Con") + class Con: """A container of a window and child containers gotten from :func:`i3ipc.Connection.get_tree()` or events. @@ -102,14 +104,14 @@ class Con: :rtype: bool """ ... - def root(self) -> Con: + def root(self: TCon) -> TCon: """Gets the root container. :returns: The root container. :rtype: :class:`Con` """ ... - def descendants(self) -> List[Con]: + def descendants(self: TCon) -> List[TCon]: """Gets a list of all child containers for the container in breadth-first order. @@ -117,7 +119,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def descendents(self) -> List[Con]: + def descendents(self: TCon) -> List[TCon]: """Gets a list of all child containers for the container in breadth-first order. @@ -128,7 +130,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def leaves(self) -> List[Con]: + def leaves(self: TCon) -> List[TCon]: """Gets a list of leaf child containers for this container in breadth-first order. Leaf containers normally contain application windows. @@ -157,14 +159,14 @@ class Con: :rtype: list(:class:`CommandReply `) """ ... - def workspaces(self) -> List[Con]: + def workspaces(self: TCon) -> List[TCon]: """Gets a list of workspace containers for this tree. :returns: A list of workspace containers. :rtype: list(:class:`Con`) """ ... - def find_focused(self) -> Optional[Con]: + def find_focused(self: TCon) -> Optional[TCon]: """Finds the focused container under this container if it exists. :returns: The focused container if it exists. @@ -172,7 +174,7 @@ class Con: under this container """ ... - def find_by_id(self, id: int) -> Optional[Con]: + def find_by_id(self: TCon, id: int) -> Optional[TCon]: """Finds a container with the given container id under this node. :returns: The container with this container id if it exists. @@ -180,14 +182,14 @@ class Con: this container id. """ ... - def find_by_pid(self, pid: int) -> List[Con]: + def find_by_pid(self: TCon, pid: int) -> List[TCon]: """Finds all the containers under this node with this pid. :returns: A list of containers with this pid. :rtype: list(:class:`Con`) """ ... - def find_by_window(self, window: int) -> Optional[Con]: + def find_by_window(self: TCon, window: int) -> Optional[TCon]: """Finds a container with the given window id under this node. :returns: The container with this window id if it exists. @@ -195,7 +197,7 @@ class Con: this window id. """ ... - def find_by_role(self, pattern: str) -> List[Con]: + def find_by_role(self: TCon, pattern: str) -> List[TCon]: """Finds all the containers under this node with a window role that matches the given regex pattern. @@ -204,7 +206,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def find_named(self, pattern: str) -> List[Con]: + def find_named(self: TCon, pattern: str) -> List[TCon]: """Finds all the containers under this node with a name that matches the given regex pattern. @@ -213,7 +215,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def find_titled(self, pattern: str) -> List[Con]: + def find_titled(self: TCon, pattern: str) -> List[TCon]: """Finds all the containers under this node with a window title that matches the given regex pattern. @@ -222,7 +224,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def find_classed(self, pattern: str) -> List[Con]: + def find_classed(self: TCon, pattern: str) -> List[TCon]: """Finds all the containers under this node with a window class, or app_id that matches the given regex pattern. @@ -231,7 +233,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def find_instanced(self, pattern: str) -> List[Con]: + def find_instanced(self: TCon, pattern: str) -> List[TCon]: """Finds all the containers under this node with a window instance that matches the given regex pattern. @@ -240,7 +242,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def find_marked(self, pattern: str = ...) -> List[Con]: + def find_marked(self: TCon, pattern: str = ...) -> List[TCon]: """Finds all the containers under this node with a mark that matches the given regex pattern. @@ -249,7 +251,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def find_fullscreen(self) -> List[Con]: + def find_fullscreen(self: TCon) -> List[TCon]: """Finds all the containers under this node that are in fullscreen mode. @@ -257,7 +259,7 @@ class Con: :rtype: list(:class:`Con`) """ ... - def workspace(self) -> Optional[Con]: + def workspace(self: TCon) -> Optional[TCon]: """Finds the workspace container for this node if this container is at or below the workspace level.