Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Aug 16, 2021
1 parent f5bc41c commit 19d0990
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[mypy]
ignore_missing_imports = True
exclude =
tests/fake_jsonplaceholder.py
docs/conf.py
8 changes: 4 additions & 4 deletions bombard/bombardier.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class Bombardier(WeaverMill):

def __init__(
self,
supply: Dict[str, Any] = None,
supply: Optional[Dict[str, Any]] = None,
args: Optional[Any] = None,
campaign_book: Dict[str, Any] = None,
ok_statuses: List[int] = None,
overload_statuses: List[int] = None,
campaign_book: Optional[Dict[str, Any]] = None,
ok_statuses: Optional[List[int]] = None,
overload_statuses: Optional[List[int]] = None,
):
self.supply = supply if supply is not None else {}
self.supply["args"] = args
Expand Down
8 changes: 4 additions & 4 deletions bombard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import os.path
from shutil import copyfile
from typing import Optional
from typing import Any, Dict, Optional, Union

import colorama

Expand All @@ -20,7 +20,7 @@
# stdout or stderr, and replace them with equivalent Win32 calls.


def guess_type(value: str):
def guess_type(value: str) -> Union[str, int, float]:
"""
Converts value in int or float if possible
"""
Expand All @@ -35,7 +35,7 @@ def guess_type(value: str):
return value


def get_supply_from_cli(supply: Optional[list]):
def get_supply_from_cli(supply: Optional[list]) -> Dict[str, Any]:
result = {}
if supply:
for item in supply:
Expand Down Expand Up @@ -140,7 +140,7 @@ def campaign(args):
start_campaign(args, yaml.load(open(campaign_file_name, "r")))


def main():
def main() -> None:
campaign(get_args())


Expand Down
21 changes: 11 additions & 10 deletions bombard/pretty_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
True
"""
from typing import Any, Optional

time_ns = None # for Python3.7+ this is function from system library time


# for earlier Python versions this is emulation of the Python3.7 time_ns


def pretty_ns(elapsed_ns: int, fixed_units: str = None) -> str:
def pretty_ns(elapsed_ns: int, fixed_units: Optional[str] = None) -> str:
dividers = {
"us": 1,
"mks": 1000,
Expand All @@ -36,7 +37,7 @@ def pretty_ns(elapsed_ns: int, fixed_units: str = None) -> str:
"hours": 60,
"days": 24,
}
result = elapsed_ns
result: float = elapsed_ns
for unit, divider in dividers.items():
result /= divider
if result < 100 or unit.lower() == fixed_units:
Expand All @@ -45,27 +46,27 @@ def pretty_ns(elapsed_ns: int, fixed_units: str = None) -> str:
return f"{result:.1f} {dividers['days']}"


def emul_time_ns():
def emul_time_ns() -> int:
return int(perf_counter() * 10 ** 9)


class Timer:
def __init__(self):
def __init__(self) -> None:
pass

def __enter__(self):
self.start = time_ns()
def __enter__(self) -> "Timer":
self.start = time_ns() # type: ignore
return self

def __exit__(self, *args):
def __exit__(self, *args: Any) -> None:
pass

@property
def ns(self):
return time_ns() - self.start
def ns(self) -> int:
return time_ns() - self.start # type: ignore

@property
def pretty(self):
def pretty(self) -> str:
return pretty_ns(self.ns)


Expand Down

0 comments on commit 19d0990

Please sign in to comment.