Skip to content

Commit

Permalink
Use real types instead of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Dec 8, 2022
1 parent 0ddd1b7 commit 870d1ac
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hai/boto3_multipart_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def upload_file(
raise TypeError('`fp` must have a `read()` method')

try:
size = os.stat(fp.fileno()).st_size # type: Optional[int]
size = os.stat(fp.fileno()).st_size
except (OSError, AttributeError):
size = None

Expand Down
4 changes: 2 additions & 2 deletions hai/event_emitter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, Optional
from typing import Any, Callable, Dict, Optional, Set

DICT_NAME = '_event_emitter_dict'

Expand All @@ -10,7 +10,7 @@ def _get_event_emitter_dict(obj: Any) -> Dict[str, Any]:


class EventEmitter:
event_types = set() # type: set[str]
event_types: Set[str] = set()

def on(self, event: str, handler: Handler) -> None:
if event != '*' and event not in self.event_types:
Expand Down
4 changes: 2 additions & 2 deletions hai/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ParallelRun:
def __init__(self, parallelism: Optional[int] = None) -> None:
self.pool = ThreadPool(processes=(parallelism or (int(os.cpu_count() or 1) * 2)))
self.task_complete_event = threading.Event()
self.tasks = [] # type: List[ApplyResult[Any]]
self.completed_tasks = WeakSet() # type: WeakSet[ApplyResult[Any]]
self.tasks: List[ApplyResult[Any]] = []
self.completed_tasks: WeakSet[ApplyResult[Any]] = WeakSet()

def __enter__(self) -> "ParallelRun":
return self
Expand Down
12 changes: 6 additions & 6 deletions hai/pipe_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BasePipePump:

def __init__(self) -> None:
self.selector = selectors.DefaultSelector()
self.buffers = {} # type: Dict[str, bytes]
self.buffers: Dict[str, bytes] = {}
self.selector_lock = threading.Lock()

def register(self, key: str, fileobj: Optional[IO[bytes]]) -> None:
Expand Down Expand Up @@ -46,7 +46,7 @@ def pump(self, timeout: float = 0, max_reads: int = 1) -> int:
read_num += 1
should_repeat = False
for (key, _event) in self.selector.select(timeout=timeout):
fileobj = key.fileobj # type: IO[bytes] # type: ignore[assignment]
fileobj: IO[bytes] = key.fileobj # type: ignore[assignment]
data = fileobj.read(self.read_size)
self.feed(key.data, data)
should_repeat = True # Got data, should try again
Expand Down Expand Up @@ -125,8 +125,8 @@ def __init__(self, separator: bytes = b'\n') -> None:
super().__init__()
assert isinstance(separator, bytes)
self.separator = separator
self.lines = {} # type: Dict[str, List[bytes]]
self._line_handlers = [] # type: List[LineHandler]
self.lines: Dict[str, List[bytes]] = {}
self._line_handlers: List[LineHandler] = []

def add_line_handler(self, handler: LineHandler) -> None:
"""
Expand Down Expand Up @@ -241,8 +241,8 @@ class CRLFPipePump(BasePipePump):

def __init__(self) -> None:
super().__init__()
self.line_state = {} # type: Dict[str, Tuple[Optional[bytes], bool]]
self._handlers = [] # type: List[CRLFHandler]
self.line_state: Dict[str, Tuple[Optional[bytes], bool]] = {}
self._handlers: List[CRLFHandler] = []

def add_handler(self, handler: CRLFHandler) -> None:
"""
Expand Down
8 changes: 4 additions & 4 deletions hai/rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def __init__(self, rate: Rate, allow_underflow: bool = False) -> None:
"""
self.rate = rate
self.allow_underflow = bool(allow_underflow)
self.last_check = None # type: Optional[float]
self.allowance = None # type: Optional[float]
self.current_state = None # type: Optional[bool]
self.last_check: Optional[float] = None
self.allowance: Optional[float] = None
self.current_state: Optional[bool] = None

@classmethod
def from_per_second(cls, per_second: int, allow_underflow: bool = False) -> "RateLimiter":
Expand Down Expand Up @@ -155,7 +155,7 @@ class MultiRateLimiter:
allow_underflow = False

def __init__(self, default_limit: Rate, per_name_limits: Optional[Dict[str, Rate]] = None) -> None:
self.limiters = {} # type: Dict[str, RateLimiter]
self.limiters: Dict[str, RateLimiter] = {}
self.default_limit = default_limit
self.per_name_limits = dict(per_name_limits or {})
assert isinstance(default_limit, Rate)
Expand Down

0 comments on commit 870d1ac

Please sign in to comment.