Skip to content

Commit

Permalink
updated after review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgor committed Mar 8, 2022
1 parent 5d5c10e commit 1694837
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ResponseContextManager(LocustResponse):
:py:meth:`failure <locust.clients.ResponseContextManager.failure>`.
"""

_manual_result: Optional[Union[bool, CatchResponseError, Exception]] = None
_manual_result: Optional[Union[bool, Exception]] = None
_entered = False

def __init__(self, response, request_event, request_meta):
Expand Down
5 changes: 1 addition & 4 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,7 @@ def json(self) -> dict:
"""
Parses the response as json and returns a dict
"""
if self.text is not None:
return json.loads(self.text)
else:
return {}
return json.loads(self.text) # type: ignore

def raise_for_status(self):
"""Raise any connection errors that occurred during the request"""
Expand Down
14 changes: 7 additions & 7 deletions locust/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def __init__(self, worker_nodes: "List[WorkerNode]", user_classes: List[Type[Use
assert len(user_classes) > 0
assert len(set(self._user_classes)) == len(self._user_classes)

self._target_user_count: int
self._target_user_count: int = None

self._spawn_rate: float
self._spawn_rate: float = None

self._user_count_per_dispatch_iteration: int
self._user_count_per_dispatch_iteration: int = None

self._wait_between_dispatch: float
self._wait_between_dispatch: float = None

self._initial_users_on_workers = {
worker_node.id: {user_class.__name__: 0 for user_class in self._user_classes}
Expand All @@ -78,7 +78,7 @@ def __init__(self, worker_nodes: "List[WorkerNode]", user_classes: List[Type[Use

self._current_user_count = self.get_current_user_count()

self._dispatcher_generator: Generator[Dict[str, Dict[str, int]], None, None]
self._dispatcher_generator: Generator[Dict[str, Dict[str, int]], None, None] = None

self._user_generator = self._user_gen()

Expand All @@ -99,7 +99,7 @@ def __init__(self, worker_nodes: "List[WorkerNode]", user_classes: List[Type[Use
self._no_user_to_spawn = False

def get_current_user_count(self) -> int:
# https://github.com/python/mypy/issues/1507
# need to ignore type due to https://github.com/python/mypy/issues/1507
return sum(map(sum, map(dict.values, self._users_on_workers.values()))) # type: ignore

@property
Expand Down Expand Up @@ -414,5 +414,5 @@ def _fast_users_on_workers_copy(users_on_workers: Dict[str, Dict[str, int]]) ->
The implementation was profiled and compared to other implementations such as dict-comprehensions
and the one below is the most efficient.
"""
# https://github.com/python/mypy/issues/1507
# type is ignored due to: https://github.com/python/mypy/issues/1507
return dict(zip(users_on_workers.keys(), map(dict.copy, users_on_workers.values()))) # type: ignore
2 changes: 0 additions & 2 deletions locust/util/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def __new__(mcs, classname, bases, class_dict):


# PEP 484 specifies "Generic metaclasses are not supported", see https://github.com/python/mypy/issues/3602, ignore typing errors


class DeprecatedLocustClass(
metaclass=deprecated_locust_meta_class( # type: ignore
"The Locust class has been renamed to User in version 1.0. "
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ ignore_missing_imports = True

[mypy-requests.*]
ignore_missing_imports = True

[mypy-locust.dispatch]
no_strict_optional = True
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ commands =
flake8 . --count --show-source --statistics
coverage run -m unittest discover []
black --check .
mypy --ignore-missing-imports locust/
mypy locust/
bash -ec 'PYTHONUNBUFFERED=1 timeout 2s python3 examples/debugging.py >out.txt 2>err.txt || true'
grep -m 1 '/hello' out.txt
bash -ec '! grep . err.txt' # should be empty
Expand Down

0 comments on commit 1694837

Please sign in to comment.