Skip to content

Commit

Permalink
Apply pyupgrade --py39-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Aug 7, 2023
1 parent 501c452 commit cc9bb12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
19 changes: 9 additions & 10 deletions mesa/batchrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
from typing import (
Any,
Dict,
Iterable,
List,
Mapping,
Optional,
Tuple,
Type,
Union,
)
from collections.abc import Iterable, Mapping

from tqdm.auto import tqdm

from mesa.model import Model


def batch_run(
model_cls: Type[Model],
model_cls: type[Model],
parameters: Mapping[str, Union[Any, Iterable[Any]]],
# We still retain the Optional[int] because users may set it to None (i.e. use all CPUs)
number_processes: Optional[int] = 1,
iterations: int = 1,
data_collection_period: int = -1,
max_steps: int = 1000,
display_progress: bool = True,
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""Batch run a mesa model with a set of parameter values.
Parameters
Expand Down Expand Up @@ -67,7 +66,7 @@ def batch_run(
data_collection_period=data_collection_period,
)

results: List[Dict[str, Any]] = []
results: list[dict[str, Any]] = []

with tqdm(total=len(runs_list), disable=not display_progress) as pbar:
if number_processes == 1:
Expand All @@ -86,7 +85,7 @@ def batch_run(

def _make_model_kwargs(
parameters: Mapping[str, Union[Any, Iterable[Any]]]
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""Create model kwargs from parameters dictionary.
Parameters
Expand Down Expand Up @@ -116,11 +115,11 @@ def _make_model_kwargs(


def _model_run_func(
model_cls: Type[Model],
run: Tuple[int, int, Dict[str, Any]],
model_cls: type[Model],
run: tuple[int, int, dict[str, Any]],
max_steps: int,
data_collection_period: int,
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""Run a single model run and collect model and agent data.
Parameters
Expand Down Expand Up @@ -185,7 +184,7 @@ def _model_run_func(
def _collect_data(
model: Model,
step: int,
) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]:
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
"""Collect model and agent data from a model using mesas datacollector."""
dc = model.datacollector

Expand Down
10 changes: 4 additions & 6 deletions mesa/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
from typing import (
Any,
Callable,
Iterable,
Iterator,
List,
Sequence,
Tuple,
TypeVar,
Union,
cast,
overload,
)
from collections.abc import Iterable, Iterator, Sequence
from warnings import warn

import networkx as nx
Expand All @@ -49,15 +47,15 @@
# for better performance, we calculate the tuple to use in the is_integer function
_types_integer = (int, np.integer)

Coordinate = Tuple[int, int]
Coordinate = tuple[int, int]
# used in ContinuousSpace
FloatCoordinate = Union[Tuple[float, float], npt.NDArray[float]]
FloatCoordinate = Union[tuple[float, float], npt.NDArray[float]]
NetworkCoordinate = int

Position = Union[Coordinate, FloatCoordinate, NetworkCoordinate]

GridContent = Union[Agent, None]
MultiGridContent = List[Agent]
MultiGridContent = list[Agent]

F = TypeVar("F", bound=Callable[..., Any])

Expand Down

0 comments on commit cc9bb12

Please sign in to comment.