Skip to content

Commit

Permalink
fix(mypy): fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alvalentini committed Oct 14, 2024
1 parent 156ae02 commit a0da9f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ grpcio-tools
grpc-stubs
pytest
pytest-cov
mypy
mypy==1.12.0
pre-commit
black==22.6.0
8 changes: 3 additions & 5 deletions unified_planning/model/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions unified_planning/model/walkers/type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion unified_planning/test/test_partial_order_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion unified_planning/test/test_plan_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a0da9f8

Please sign in to comment.