Type fixes (#979)
* Type fixes * Type fix * Py class role * unused any import
This commit is contained in:
parent
dd2476f02a
commit
41ba50443d
|
@ -31,5 +31,4 @@ htmlcov
|
|||
dist
|
||||
build
|
||||
|
||||
proxy/public
|
||||
profile.svg
|
||||
|
|
|
@ -12,6 +12,7 @@ coverage:
|
|||
# target: 100% # we always want 100% coverage here
|
||||
paths:
|
||||
- "tests/" # only include coverage in "tests/" folder
|
||||
threshold: 1%
|
||||
lib: # declare a new status context "lib"
|
||||
paths:
|
||||
- "!tests/" # remove all files in "tests/"
|
||||
|
|
|
@ -312,6 +312,7 @@ nitpick_ignore = [
|
|||
(_py_class_role, 'Work'),
|
||||
(_py_class_role, 'proxy.core.acceptor.work.Work'),
|
||||
(_py_class_role, 'connection.Connection'),
|
||||
(_py_class_role, 'EventQueue'),
|
||||
(_py_obj_role, 'proxy.core.work.threadless.T'),
|
||||
(_py_obj_role, 'proxy.core.work.work.T'),
|
||||
]
|
||||
|
|
|
@ -13,16 +13,16 @@ import argparse
|
|||
import multiprocessing
|
||||
|
||||
from multiprocessing import connection
|
||||
|
||||
from typing import Any, Optional, List
|
||||
from typing import TYPE_CHECKING, Any, Optional, List
|
||||
|
||||
from .remote import RemoteExecutor
|
||||
|
||||
from ..event import EventQueue
|
||||
|
||||
from ...common.flag import flags
|
||||
from ...common.constants import DEFAULT_NUM_WORKERS, DEFAULT_THREADLESS
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..event import EventQueue
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -71,7 +71,7 @@ class ThreadlessPool:
|
|||
def __init__(
|
||||
self,
|
||||
flags: argparse.Namespace,
|
||||
event_queue: Optional[EventQueue] = None,
|
||||
event_queue: Optional['EventQueue'] = None,
|
||||
) -> None:
|
||||
self.flags = flags
|
||||
self.event_queue = event_queue
|
||||
|
|
|
@ -12,7 +12,6 @@ import asyncio
|
|||
import logging
|
||||
|
||||
from typing import Optional, Any
|
||||
|
||||
from multiprocessing import connection
|
||||
from multiprocessing.reduction import recv_handle
|
||||
|
||||
|
|
|
@ -11,13 +11,15 @@
|
|||
import socket
|
||||
import argparse
|
||||
import threading
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from .work import Work
|
||||
from typing import TYPE_CHECKING, Optional, Tuple
|
||||
|
||||
from ..connection import TcpClientConnection
|
||||
from ..event import EventQueue, eventNames
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .work import Work
|
||||
|
||||
|
||||
def start_threaded_work(
|
||||
flags: argparse.Namespace,
|
||||
|
@ -25,7 +27,7 @@ def start_threaded_work(
|
|||
addr: Optional[Tuple[str, int]],
|
||||
event_queue: Optional[EventQueue] = None,
|
||||
publisher_id: Optional[str] = None,
|
||||
) -> Tuple[Work[TcpClientConnection], threading.Thread]:
|
||||
) -> Tuple['Work[TcpClientConnection]', threading.Thread]:
|
||||
"""Utility method to start a work in a new thread."""
|
||||
work = flags.work_klass(
|
||||
TcpClientConnection(conn, addr),
|
||||
|
|
|
@ -18,7 +18,7 @@ import selectors
|
|||
import multiprocessing
|
||||
|
||||
from abc import abstractmethod, ABC
|
||||
from typing import Any, Dict, Optional, Tuple, List, Set, Generic, TypeVar, Union
|
||||
from typing import TYPE_CHECKING, Dict, Optional, Tuple, List, Set, Generic, TypeVar, Union
|
||||
|
||||
from ...common.logger import Logger
|
||||
from ...common.types import Readables, SelectableEvents, Writables
|
||||
|
@ -26,9 +26,13 @@ from ...common.constants import DEFAULT_INACTIVE_CONN_CLEANUP_TIMEOUT, DEFAULT_S
|
|||
from ...common.constants import DEFAULT_WAIT_FOR_TASKS_TIMEOUT
|
||||
|
||||
from ..connection import TcpClientConnection, UpstreamConnectionPool
|
||||
from ..event import eventNames, EventQueue
|
||||
from ..event import eventNames
|
||||
|
||||
from .work import Work
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
|
||||
from ..event import EventQueue
|
||||
from .work import Work
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
@ -62,7 +66,7 @@ class Threadless(ABC, Generic[T]):
|
|||
iid: str,
|
||||
work_queue: T,
|
||||
flags: argparse.Namespace,
|
||||
event_queue: Optional[EventQueue] = None,
|
||||
event_queue: Optional['EventQueue'] = None,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.iid = iid
|
||||
|
@ -71,7 +75,7 @@ class Threadless(ABC, Generic[T]):
|
|||
self.event_queue = event_queue
|
||||
|
||||
self.running = multiprocessing.Event()
|
||||
self.works: Dict[int, Work[Any]] = {}
|
||||
self.works: Dict[int, 'Work[Any]'] = {}
|
||||
self.selector: Optional[selectors.DefaultSelector] = None
|
||||
# If we remove single quotes for typing hint below,
|
||||
# runtime exceptions will occur for < Python 3.9.
|
||||
|
|
Loading…
Reference in New Issue