biosustain/optlang

View on GitHub

Showing 157 of 209 total issues

Function build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def build(self, add_variable_constraints=False):
        """Build the problem instance.

        Parameters
        ----------
Severity: Minor
Found in src/optlang/matrix_interface.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function get_root has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def get_root() -> str:
    """Get the project root directory.

    We require that all commands are run from the project root, i.e. the
    directory that contains setup.py, setup.cfg, and versioneer.py .
Severity: Minor
Found in versioneer.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function primal has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def primal(self):
        if getattr(self, "problem", None) is not None and self.problem.status == interface.OPTIMAL:
            if self.lb is not None:
                primal = self.lb + self.problem.problem.get_constraint_slack(self.lower_constraint_name)
                return primal
Severity: Minor
Found in src/optlang/scipy_interface.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _constraint_lb_and_ub_to_cplex_sense_rhs_and_range_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def _constraint_lb_and_ub_to_cplex_sense_rhs_and_range_value(lb, ub):
    """Helper function used by Constraint and Model"""
    if lb is None and ub is None:
        raise Exception("Free constraint ...")
    elif lb is None:
Severity: Minor
Found in src/optlang/cplex_interface.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function objective has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def objective(self, value):
        value.problem = None
        if self._objective is not None:
            variables = self.objective.variables
            for variable in variables:
Severity: Minor
Found in src/optlang/glpk_interface.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _constraint_lb_and_ub_to_gurobi_sense_rhs_and_range_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def _constraint_lb_and_ub_to_gurobi_sense_rhs_and_range_value(lb, ub):
    """Helper function used by Constraint and Model"""
    if lb is None and ub is None:
        raise Exception("Free constraint ...")
    elif lb is None:
Severity: Minor
Found in src/optlang/gurobi_interface.py - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid too many return statements within this function.
Open

                            return False
Severity: Major
Found in src/optlang/interface.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return {"type": "Number", "value": float(expr)}
    Severity: Major
    Found in src/optlang/util.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return {"type": "Number", "value": int(expr)}
      Severity: Major
      Found in src/optlang/util.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return False
        Severity: Major
        Found in src/optlang/interface.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return symbolics.sympify(expr["value"])
          Severity: Major
          Found in src/optlang/util.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return symbolics.Symbol(expr["name"])
            Severity: Major
            Found in src/optlang/util.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return is_quad
              Severity: Major
              Found in src/optlang/interface.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return {"type": "Number", "value": expr}
                Severity: Major
                Found in src/optlang/util.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return {"version": "0+unknown", "full-revisionid": None,
                  Severity: Major
                  Found in src/optlang/_version.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return poly.is_quadratic
                    Severity: Major
                    Found in src/optlang/interface.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return {"version": "0+unknown", "full-revisionid": None,
                      Severity: Major
                      Found in versioneer.py - About 30 mins to fix

                        Function __setstate__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def __setstate__(self, state):
                                for key, val in state.items():
                                    if key != "tolerances":
                                        setattr(self, key, val)
                                for key, val in state["tolerances"].items():
                        Severity: Minor
                        Found in src/optlang/gurobi_interface.py - About 25 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Function coefficient_dict has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def coefficient_dict(self):
                                if self.expression.is_Add:
                                    coefficient_dict = {variable: coef for variable, coef in
                                                        self.expression.as_coefficients_dict().items() if variable.is_Symbol}
                                elif self.expression.is_Atom and self.expression.is_Symbol:
                        Severity: Minor
                        Found in src/optlang/scipy_interface.py - About 25 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Function objective has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def objective(self, value):
                                value.problem = None
                                if self._objective is not None:  # Reset previous objective
                                    self.problem.obj_linear_coefs = dict()
                                    self.problem.obj_quadratic_coefs = dict()
                        Severity: Minor
                        Found in src/optlang/matrix_interface.py - About 25 mins to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Severity
                        Category
                        Status
                        Source
                        Language