wc_lang/transform/split_reversible_reactions.py
Function run
has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring. Open
Open
def run(self, model):
""" Split reversible reactions in submodels into separate forward and backward reactions
Args:
model (:obj:`Model`): model definition
- Read upRead up
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 deeply nested control flow statements. Open
Open
for ot_token in parsed_expr._obj_tables_tokens:
if (ot_token.code == ObjTablesTokenCodes.obj_id and
issubclass(ot_token.model_type, Reaction) and
ot_token.model_id == rxn.id):
new_obj_expr_elements.append(f'({rxn_for.id} - {rxn_bck.id})')
Avoid deeply nested control flow statements. Open
Open
if part_back:
rxn_bck.participants.append(part_back)
else:
rxn_bck.participants.create(species=part.species, coefficient=-1 * part.coefficient)
Avoid deeply nested control flow statements. Open
Open
if rxn.flux_bounds:
if not math.isnan(rxn.flux_bounds.min) and not math.isnan(rxn.flux_bounds.max):
# assume flux_bounds.min <= flux_bounds.max
assert rxn.flux_bounds.min <= rxn.flux_bounds.max, \
f"min flux bound greater than max in {rxn.id}"