mypy: Disable implicit optionals

This commit is contained in:
2021-04-07 21:36:37 -05:00
parent e9cd6d1715
commit 157825a345
9 changed files with 23 additions and 14 deletions

View File

@@ -4,3 +4,4 @@ disallow_untyped_defs = True
disallow_untyped_calls = True disallow_untyped_calls = True
disallow_incomplete_defs = True disallow_incomplete_defs = True
pretty = True pretty = True
no_implicit_optional = True

View File

@@ -58,7 +58,7 @@ class AdaptiveClassifier(Classifier):
def __init__( def __init__(
self, self,
candidates: Dict[str, CandidateClassifierSpecs] = None, candidates: Optional[Dict[str, CandidateClassifierSpecs]] = None,
) -> None: ) -> None:
super().__init__() super().__init__()
if candidates is None: if candidates is None:

View File

@@ -149,9 +149,9 @@ class GurobiSolver(InternalSolver):
def solve( def solve(
self, self,
tee: bool = False, tee: bool = False,
iteration_cb: IterationCallback = None, iteration_cb: Optional[IterationCallback] = None,
lazy_cb: LazyCallback = None, lazy_cb: Optional[LazyCallback] = None,
user_cut_cb: UserCutCallback = None, user_cut_cb: Optional[UserCutCallback] = None,
) -> MIPSolveStats: ) -> MIPSolveStats:
self._raise_if_callback() self._raise_if_callback()
assert self.model is not None assert self.model is not None

View File

@@ -52,9 +52,9 @@ class InternalSolver(ABC, EnforceOverrides):
def solve( def solve(
self, self,
tee: bool = False, tee: bool = False,
iteration_cb: IterationCallback = None, iteration_cb: Optional[IterationCallback] = None,
lazy_cb: LazyCallback = None, lazy_cb: Optional[LazyCallback] = None,
user_cut_cb: UserCutCallback = None, user_cut_cb: Optional[UserCutCallback] = None,
) -> MIPSolveStats: ) -> MIPSolveStats:
""" """
Solves the currently loaded instance. After this method finishes, Solves the currently loaded instance. After this method finishes,

View File

@@ -93,9 +93,9 @@ class LearningSolver:
def __init__( def __init__(
self, self,
components: List[Component] = None, components: Optional[List[Component]] = None,
mode: str = "exact", mode: str = "exact",
solver: InternalSolver = None, solver: Optional[InternalSolver] = None,
use_lazy_cb: bool = False, use_lazy_cb: bool = False,
solve_lp: bool = True, solve_lp: bool = True,
simulate_perfect: bool = False, simulate_perfect: bool = False,

View File

@@ -88,9 +88,9 @@ class BasePyomoSolver(InternalSolver):
def solve( def solve(
self, self,
tee: bool = False, tee: bool = False,
iteration_cb: IterationCallback = None, iteration_cb: Optional[IterationCallback] = None,
lazy_cb: LazyCallback = None, lazy_cb: Optional[LazyCallback] = None,
user_cut_cb: UserCutCallback = None, user_cut_cb: Optional[UserCutCallback] = None,
) -> MIPSolveStats: ) -> MIPSolveStats:
if lazy_cb is not None: if lazy_cb is not None:
raise Exception("lazy callback not currently supported") raise Exception("lazy callback not currently supported")

View File

@@ -28,7 +28,7 @@ class GurobiPyomoSolver(BasePyomoSolver):
def __init__( def __init__(
self, self,
params: SolverParams = None, params: Optional[SolverParams] = None,
) -> None: ) -> None:
if params is None: if params is None:
params = {} params = {}

View File

@@ -3,6 +3,7 @@
# Released under the modified BSD license. See COPYING.md for more details. # Released under the modified BSD license. See COPYING.md for more details.
import logging import logging
from typing import Optional
from overrides import overrides from overrides import overrides
from pyomo import environ as pe from pyomo import environ as pe
@@ -25,7 +26,10 @@ class XpressPyomoSolver(BasePyomoSolver):
{"Threads": 4} to set the number of threads. {"Threads": 4} to set the number of threads.
""" """
def __init__(self, params: SolverParams = None) -> None: def __init__(
self,
params: Optional[SolverParams] = None,
) -> None:
if params is None: if params is None:
params = {} params = {}
params["randomseed"] = randint(low=0, high=1000).rvs() params["randomseed"] = randint(low=0, high=1000).rvs()

View File

@@ -38,6 +38,10 @@ def test_learning_solver() -> None:
assert sample.lower_bound == 1183.0 assert sample.lower_bound == 1183.0
assert sample.upper_bound == 1183.0 assert sample.upper_bound == 1183.0
assert sample.lp_solution is not None assert sample.lp_solution is not None
assert sample.lp_solution["x[0]"] is not None
assert sample.lp_solution["x[1]"] is not None
assert sample.lp_solution["x[2]"] is not None
assert sample.lp_solution["x[3]"] is not None
assert round(sample.lp_solution["x[0]"], 3) == 1.000 assert round(sample.lp_solution["x[0]"], 3) == 1.000
assert round(sample.lp_solution["x[1]"], 3) == 0.923 assert round(sample.lp_solution["x[1]"], 3) == 0.923
assert round(sample.lp_solution["x[2]"], 3) == 1.000 assert round(sample.lp_solution["x[2]"], 3) == 1.000