Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mypy): fix typing errors #638

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading