Skip to content

Commit

Permalink
fstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
whoburg committed Jan 5, 2024
1 parent af3c216 commit 6f60ba8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions gpkit/constraints/model.py
Expand Up @@ -9,6 +9,8 @@
from ..exceptions import InvalidGPConstraint
from .. import NamedVariables
from ..tools.docstring import expected_unbounded
from .relax import ConstantsRelaxed, ConstraintsRelaxed
from .bounded import Bounded
from .set import add_meq_bounds
from ..exceptions import Infeasible

Expand Down Expand Up @@ -40,6 +42,7 @@ class Model(CostedConstraintSet):
solution = None

def __init__(self, cost=None, constraints=None, *args, **kwargs):
#pylint: disable=keyword-arg-before-vararg
setup_vars = None
substitutions = kwargs.pop("substitutions", None) # reserved keyword
if hasattr(self, "setup"):
Expand Down Expand Up @@ -81,7 +84,7 @@ def __init__(self, cost=None, constraints=None, *args, **kwargs):

def verify_docstring(self): # pylint:disable=too-many-locals,too-many-branches,too-many-statements
"Verifies docstring bounds are sufficient but not excessive."
err = "while verifying %s:\n" % self.__class__.__name__
err = f"while verifying {self.__class__.__name__}:\n"
bounded, meq_bounded = self.bounded.copy(), self.meq_bounded.copy()
doc = self.__class__.__doc__
exp_unbounds = expected_unbounded(self, doc)
Expand All @@ -93,8 +96,8 @@ def verify_docstring(self): # pylint:disable=too-many-locals,too-many-branches,
continue
badvks = ", ".join(str(v) for v in badvks)
badvks += (" were" if len(badvks) > 1 else " was")
err += (" %s %s-bounded; expected %s-unbounded"
"\n" % (badvks, direction, direction))
err += (f" {badvks} {direction}-bounded; expected "
f"{direction}-unbounded\n")
raise ValueError(err)
bounded.update(exp_unbounds) # if not, treat expected as bounded
add_meq_bounds(bounded, meq_bounded) # and add more meqs
Expand All @@ -117,15 +120,16 @@ def verify_docstring(self): # pylint:disable=too-many-locals,too-many-branches,
if (key, bound) not in self.missingbounds:
self.missingbounds[(key, bound)] = ""
if self.missingbounds: # anything unbounded? err!
boundstrs = "\n".join(" %s has no %s bound%s" % (v, b, x)
boundstrs = "\n".join(f" {v} has no {b} bound{x}"
for (v, b), x
in self.missingbounds.items())
docstring = ("To fix this add the following to %s's"
" docstring (you may not need it all):"
" \n" % self.__class__.__name__)
docstring = ("To fix this add the following to "
f"{self.__class__.__name__}'s docstring "
"(you may not need it all):\n")
for direction in ["upper", "lower"]:
mb = [k for (k, b) in self.missingbounds if b == direction]
if mb:
#pylint: disable=consider-using-f-string
docstring += """
%s Unbounded
---------------
Expand Down Expand Up @@ -165,8 +169,6 @@ def autosweep(self, sweeps, tol=0.01, samplepoints=100, **solveargs):

def debug(self, solver=None, verbosity=1, **solveargs):
"Attempts to diagnose infeasible models."
from .relax import ConstantsRelaxed, ConstraintsRelaxed
from .bounded import Bounded

sol = None
solveargs["solver"] = solver
Expand Down

0 comments on commit 6f60ba8

Please sign in to comment.