Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
working pre-commit/dmypy config
  • Loading branch information
andgineer committed Aug 9, 2021
1 parent a475b44 commit 56e3bf7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ repos:
entry: dmypy
files: \.py$
language: python
require_serial: true
args: ["run", "--", "--strict", "--implicit-reexport", "--warn-unused-ignores", "--cache-fine-grained"]

- id: pylint
Expand Down
6 changes: 5 additions & 1 deletion bombard/pretty_sz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
def pretty_sz(size: int) -> str:
from typing import Union


def pretty_sz(size: Union[int, float]) -> str:
dividers = {
"bytes": 1,
"kb": 1024,
Expand All @@ -12,3 +15,4 @@ def pretty_sz(size: int) -> str:
if result < 100:
return f"{result:.1f} {unit}"
result = round(result)
return f"{result:.1f} {dividers['pb']}"
2 changes: 1 addition & 1 deletion bombard/show_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@


def markdown_for_terminal(descr: str) -> str:
return highlight(descr, MarkdownLexer(), TerminalFormatter())
return str(highlight(descr, MarkdownLexer(), TerminalFormatter()))
13 changes: 7 additions & 6 deletions bombard/weaver_mill.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from copy import deepcopy
from queue import Queue
from threading import Thread
from typing import Any, Dict


class WeaverMill:
Expand All @@ -18,15 +19,15 @@ def __init__(self, threads_num: int = 10):
"""
self.threads_num = threads_num
self.threads = []
self.queue = Queue()
self.queue: Queue = Queue()
self.job_count = 0
for thread_id in range(threads_num):
t = Thread(target=self.thread_worker, args=[thread_id])
t.daemon = True
t.start()
self.threads.append(t)

def thread_worker(self, thread_id):
def thread_worker(self, thread_id: int) -> None:
"""
Get job from queue and pass it to abstract worker
that should be implemented in descendant.
Expand All @@ -45,26 +46,26 @@ def thread_worker(self, thread_id):
self.queue.task_done()

@abstractmethod
def worker(self, thread_id, job):
def worker(self, thread_id: int, job: Dict[str, Any]) -> None:
"""
Implement your job processor, runs in thread.
:param thread_id: just sequential number of the thread we work into
:param job: job from queue
"""

def put(self, job):
def put(self, job: Dict[str, Any]) -> None:
"""
Add job to queue.
To start processing use `process`.
"""
self.queue.put(job)

def process(self):
def process(self) -> None:
""" Starts all threads and lock until queue is empty """
self.queue.join()

def stop(self):
def stop(self) -> None:
""" Stops all threads - send stop signal to queue and lock until they stop """
for _ in self.threads:
self.queue.put(None)
Expand Down
2 changes: 1 addition & 1 deletion lint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dmypy start -- --use-fine-grained-cache
#dmypy start -- --use-fine-grained-cache
#dmypy run --verbose -- --strict --implicit-reexport --warn-unused-ignores --cache-fine-grained .
(time pre-commit run --verbose --all-files) 2>&1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pyyaml>=5.1
pygments
colorama
types-PyYAML

0 comments on commit 56e3bf7

Please sign in to comment.