From df35b91c894a42c1618b6a50375e4e6bc27b8d60 Mon Sep 17 00:00:00 2001 From: Pip Liggins Date: Tue, 28 Nov 2023 11:23:56 +0000 Subject: [PATCH] Fix ruff errors --- pybamm/expression_tree/operations/serialise.py | 10 ++++++---- pybamm/simulation.py | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pybamm/expression_tree/operations/serialise.py b/pybamm/expression_tree/operations/serialise.py index cd2ff15c3d..c7768217a3 100644 --- a/pybamm/expression_tree/operations/serialise.py +++ b/pybamm/expression_tree/operations/serialise.py @@ -7,6 +7,8 @@ import numpy as np import re +from typing import Optional + class Serialise: """ @@ -78,9 +80,9 @@ class _EmptyDict(dict): def save_model( self, model: pybamm.BaseModel, - mesh: pybamm.Mesh = None, - variables: pybamm.FuzzyDict = None, - filename: str = None, + mesh: Optional[pybamm.Mesh] = None, + variables: Optional[pybamm.FuzzyDict] = None, + filename: Optional[str] = None, ): """Saves a discretised model to a JSON file. @@ -142,7 +144,7 @@ def save_model( json.dump(model_json, f) def load_model( - self, filename: str, battery_model: pybamm.BaseModel = None + self, filename: str, battery_model: Optional[pybamm.BaseModel] = None ) -> pybamm.BaseModel: """ Loads a discretised, ready to solve model into PyBaMM. diff --git a/pybamm/simulation.py b/pybamm/simulation.py index 4fe9c32924..83a386fe98 100644 --- a/pybamm/simulation.py +++ b/pybamm/simulation.py @@ -10,6 +10,7 @@ from functools import lru_cache from datetime import timedelta from pybamm.util import have_optional_dependency +from typing import Optional from pybamm.expression_tree.operations.serialise import Serialise @@ -795,7 +796,9 @@ def solve( # Hacky patch to allow correct processing of end_time and next_starting time # For efficiency purposes, op_conds treats identical steps as the same object # regardless of the initial time. Should be refactored as part of #3176 - op_conds_unproc = self.experiment.operating_conditions_steps_unprocessed[idx] + op_conds_unproc = ( + self.experiment.operating_conditions_steps_unprocessed[idx] + ) start_time = current_solution.t[-1] @@ -1192,7 +1195,7 @@ def save(self, filename): def save_model( self, - filename: str = None, + filename: Optional[str] = None, mesh: bool = False, variables: bool = False, ):