mypy: Disable implicit optionals

master
Alinson S. Xavier 5 years ago
parent e9cd6d1715
commit 157825a345
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -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

@ -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:

@ -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

@ -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,

@ -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,

@ -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")

@ -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 = {}

@ -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()

@ -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

Loading…
Cancel
Save