From a0da9f8f0cb05f11b307853f217a6de3687fd550 Mon Sep 17 00:00:00 2001 From: Alessandro Valentini Date: Mon, 14 Oct 2024 14:01:46 +0200 Subject: [PATCH] fix(mypy): fix typing errors --- dev-requirements.txt | 2 +- unified_planning/model/problem.py | 8 +++----- unified_planning/model/walkers/type_checker.py | 8 ++++++++ unified_planning/test/test_partial_order_plan.py | 4 +++- unified_planning/test/test_plan_validator.py | 4 +++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index f716462e9..4e349f7e7 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,6 +4,6 @@ grpcio-tools grpc-stubs pytest pytest-cov -mypy +mypy==1.12.0 pre-commit black==22.6.0 diff --git a/unified_planning/model/problem.py b/unified_planning/model/problem.py index 3f1552b15..f4e0c043c 100644 --- a/unified_planning/model/problem.py +++ b/unified_planning/model/problem.py @@ -1062,11 +1062,9 @@ def update_problem_kind_metric( elif metric.is_minimize_action_costs(): assert isinstance(metric, up.model.metrics.MinimizeActionCosts) self.kind.set_quality_metrics("ACTIONS_COST") - costs = ( - metric.costs.values() - if metric.default is None - else chain(metric.costs.values(), [metric.default]) - ) + costs = list(metric.costs.values()) + if metric.default is not None: + costs.append(metric.default) for cost in costs: if cost is None: raise UPProblemDefinitionError( diff --git a/unified_planning/model/walkers/type_checker.py b/unified_planning/model/walkers/type_checker.py index 2380a233a..396c45e8c 100644 --- a/unified_planning/model/walkers/type_checker.py +++ b/unified_planning/model/walkers/type_checker.py @@ -263,8 +263,12 @@ def walk_minus(self, expression, args): if upper == float("inf"): upper = None if has_real: + lower = cast(Optional[Fraction], lower) + upper = cast(Optional[Fraction], upper) return self.environment.type_manager.RealType(lower, upper) else: + lower = cast(Optional[int], lower) + upper = cast(Optional[int], upper) return self.environment.type_manager.IntType(lower, upper) def walk_times(self, expression, args): @@ -294,8 +298,12 @@ def walk_times(self, expression, args): ): upper = None if has_real: + lower = cast(Optional[Fraction], lower) + upper = cast(Optional[Fraction], upper) return self.environment.type_manager.RealType(lower, upper) else: + lower = cast(Optional[int], lower) + upper = cast(Optional[int], upper) return self.environment.type_manager.IntType(lower, upper) def walk_div(self, expression, args): diff --git a/unified_planning/test/test_partial_order_plan.py b/unified_planning/test/test_partial_order_plan.py index a233d368e..9df20bdc0 100644 --- a/unified_planning/test/test_partial_order_plan.py +++ b/unified_planning/test/test_partial_order_plan.py @@ -36,7 +36,9 @@ def test_all(self): assert validator is not None for example in self.problems.values(): problem, plans = example.problem, example.valid_plans - plan = plans[0] if plans else None + if not plans: + continue + plan = plans[0] if validator.supports(problem.kind): self.assertTrue(isinstance(plan, up.plans.SequentialPlan)) pop_plan = plan.convert_to(PlanKind.PARTIAL_ORDER_PLAN, problem) diff --git a/unified_planning/test/test_plan_validator.py b/unified_planning/test/test_plan_validator.py index 66fc2209d..a4c7c5cdd 100644 --- a/unified_planning/test/test_plan_validator.py +++ b/unified_planning/test/test_plan_validator.py @@ -71,7 +71,9 @@ def test_all_from_factory(self): def test_all_from_factory_with_problem_kind(self): for p in self.problems.values(): problem, plans = p.problem, p.valid_plans - plan = plans[0] if plans else None + if not plans: + continue + plan = plans[0] pk = problem.kind if SequentialPlanValidator.supports(pk): environment = unified_planning.environment.Environment()