Skip to content

Commit 41ba504

Browse files
authored
Type fixes (#979)
* Type fixes * Type fix * Py class role * unused any import
1 parent dd2476f commit 41ba504

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ htmlcov
3131
dist
3232
build
3333

34-
proxy/public
3534
profile.svg

codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ coverage:
1212
# target: 100% # we always want 100% coverage here
1313
paths:
1414
- "tests/" # only include coverage in "tests/" folder
15+
threshold: 1%
1516
lib: # declare a new status context "lib"
1617
paths:
1718
- "!tests/" # remove all files in "tests/"

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@
312312
(_py_class_role, 'Work'),
313313
(_py_class_role, 'proxy.core.acceptor.work.Work'),
314314
(_py_class_role, 'connection.Connection'),
315+
(_py_class_role, 'EventQueue'),
315316
(_py_obj_role, 'proxy.core.work.threadless.T'),
316317
(_py_obj_role, 'proxy.core.work.work.T'),
317318
]

proxy/core/work/pool.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import multiprocessing
1414

1515
from multiprocessing import connection
16-
17-
from typing import Any, Optional, List
16+
from typing import TYPE_CHECKING, Any, Optional, List
1817

1918
from .remote import RemoteExecutor
2019

21-
from ..event import EventQueue
22-
2320
from ...common.flag import flags
2421
from ...common.constants import DEFAULT_NUM_WORKERS, DEFAULT_THREADLESS
2522

23+
if TYPE_CHECKING:
24+
from ..event import EventQueue
25+
2626
logger = logging.getLogger(__name__)
2727

2828

@@ -71,7 +71,7 @@ class ThreadlessPool:
7171
def __init__(
7272
self,
7373
flags: argparse.Namespace,
74-
event_queue: Optional[EventQueue] = None,
74+
event_queue: Optional['EventQueue'] = None,
7575
) -> None:
7676
self.flags = flags
7777
self.event_queue = event_queue

proxy/core/work/remote.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import logging
1313

1414
from typing import Optional, Any
15-
1615
from multiprocessing import connection
1716
from multiprocessing.reduction import recv_handle
1817

proxy/core/work/threaded.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@
1111
import socket
1212
import argparse
1313
import threading
14-
from typing import Optional, Tuple
1514

16-
from .work import Work
15+
from typing import TYPE_CHECKING, Optional, Tuple
1716

1817
from ..connection import TcpClientConnection
1918
from ..event import EventQueue, eventNames
2019

20+
if TYPE_CHECKING:
21+
from .work import Work
22+
2123

2224
def start_threaded_work(
2325
flags: argparse.Namespace,
2426
conn: socket.socket,
2527
addr: Optional[Tuple[str, int]],
2628
event_queue: Optional[EventQueue] = None,
2729
publisher_id: Optional[str] = None,
28-
) -> Tuple[Work[TcpClientConnection], threading.Thread]:
30+
) -> Tuple['Work[TcpClientConnection]', threading.Thread]:
2931
"""Utility method to start a work in a new thread."""
3032
work = flags.work_klass(
3133
TcpClientConnection(conn, addr),

proxy/core/work/threadless.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,21 @@
1818
import multiprocessing
1919

2020
from abc import abstractmethod, ABC
21-
from typing import Any, Dict, Optional, Tuple, List, Set, Generic, TypeVar, Union
21+
from typing import TYPE_CHECKING, Dict, Optional, Tuple, List, Set, Generic, TypeVar, Union
2222

2323
from ...common.logger import Logger
2424
from ...common.types import Readables, SelectableEvents, Writables
2525
from ...common.constants import DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT, DEFAULT_SELECTOR_SELECT_TIMEOUT
2626
from ...common.constants import DEFAULT_WAIT_FOR_TASKS_TIMEOUT
2727

2828
from ..connection import TcpClientConnection, UpstreamConnectionPool
29-
from ..event import eventNames, EventQueue
29+
from ..event import eventNames
3030

31-
from .work import Work
31+
if TYPE_CHECKING:
32+
from typing import Any
33+
34+
from ..event import EventQueue
35+
from .work import Work
3236

3337
T = TypeVar('T')
3438

@@ -62,7 +66,7 @@ def __init__(
6266
iid: str,
6367
work_queue: T,
6468
flags: argparse.Namespace,
65-
event_queue: Optional[EventQueue] = None,
69+
event_queue: Optional['EventQueue'] = None,
6670
) -> None:
6771
super().__init__()
6872
self.iid = iid
@@ -71,7 +75,7 @@ def __init__(
7175
self.event_queue = event_queue
7276

7377
self.running = multiprocessing.Event()
74-
self.works: Dict[int, Work[Any]] = {}
78+
self.works: Dict[int, 'Work[Any]'] = {}
7579
self.selector: Optional[selectors.DefaultSelector] = None
7680
# If we remove single quotes for typing hint below,
7781
# runtime exceptions will occur for < Python 3.9.

0 commit comments

Comments
 (0)