Skip to content

Commit 0838de1

Browse files
fix circular import
1 parent 179170f commit 0838de1

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

i3ipc/_private/pubsub.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
from typing import Callable, Optional, TypeAlias, TypedDict, TypeVar
1+
from typing import Callable, Optional, TypeAlias, TypedDict, TypeVar, TYPE_CHECKING
2+
23

3-
from i3ipc.connection import Connection
44
from i3ipc.events import IpcBaseEvent
55

6+
if TYPE_CHECKING:
7+
from i3ipc.connection import Connection
8+
69
_BaseEvent = TypeVar('_BaseEvent', bound=IpcBaseEvent, contravariant=True)
710

8-
Handler: TypeAlias = Callable[[Connection, _BaseEvent], None]
11+
Handler: TypeAlias = Callable[['Connection', _BaseEvent], None]
912

1013

1114
class Subscription(TypedDict):
@@ -15,7 +18,7 @@ class Subscription(TypedDict):
1518

1619

1720
class PubSub(object):
18-
def __init__(self, conn: Connection):
21+
def __init__(self, conn: 'Connection'):
1922
self.conn = conn
2023
self._subscriptions: list[Subscription] = []
2124

i3ipc/con.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import re
22
import sys
3-
from .connection import Connection
43
from .model import Rect, Gaps
54
from . import replies
65
from collections import deque
7-
from typing import Any, cast, Generic, Literal, Optional, TypeVar
6+
from typing import Any, cast, Generic, Literal, Optional, TypeVar, TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from .connection import Connection
810

911
_Con = TypeVar('_Con', bound='Con')
1012

@@ -121,7 +123,7 @@ class Con(Generic[_Con]):
121123
representation: str
122124
visible: bool
123125

124-
def __init__(self: _Con, data: dict[str, Any], parent: _Con, conn: Connection):
126+
def __init__(self: _Con, data: dict[str, Any], parent: _Con, conn: 'Connection'):
125127
self.ipc_data = data
126128
self._conn = conn
127129
self.parent = parent

i3ipc/events.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from . import con, connection
1+
from . import con
22
from .replies import BarConfigReply, InputReply
33
from enum import Enum
4-
from typing import Any, Optional
4+
from typing import Any, Optional, TYPE_CHECKING
5+
6+
if TYPE_CHECKING:
7+
from .connection import Connection
58

69

710
class IpcBaseEvent:
@@ -66,7 +69,7 @@ class WorkspaceEvent(IpcBaseEvent):
6669
:ivar ipc_data: The raw data from the i3 ipc.
6770
:vartype ipc_data: dict
6871
"""
69-
def __init__(self, data: dict[str, Any], conn: connection.Connection, _Con=con.Con):
72+
def __init__(self, data: dict[str, Any], conn: 'Connection', _Con=con.Con):
7073
self.ipc_data = data
7174
self.change: str = data['change']
7275
self.current: Optional[con.Con] = None
@@ -127,7 +130,7 @@ class WindowEvent(IpcBaseEvent):
127130
:ivar ipc_data: The raw data from the i3 ipc.
128131
:vartype ipc_data: dict
129132
"""
130-
def __init__(self, data: dict[str, Any], conn: connection.Connection, _Con=con.Con):
133+
def __init__(self, data: dict[str, Any], conn: 'Connection', _Con=con.Con):
131134
self.ipc_data = data
132135
self.change: str = data['change']
133136
self.container = _Con(data['container'], None, conn)

0 commit comments

Comments
 (0)