Skip to content

[Feature] property overload Reaction.lower_bounds/upper_bounds #1403

@oxinabox

Description

@oxinabox

Checklist

Problem

I want it to be impossible to set a Reaction's lower_bound and upper_bound inconsistently.

That is to say if the lower-bound is ever set to above the current upper-bound I want the upper-bound to also be updated, and visa versa

Solution

If we user property setter overloads we could accomplish this by overloading what happens when you set either of them.

Alternatives

This is the code am currently using

def set_lower_bound(reaction: Reaction, lower_bound: float) -> None:
    if reaction.upper_bound < lower_bound:
        reaction.upper_bound = lower_bound
    reaction.lower_bound = lower_bound


def set_upper_bound(reaction: Reaction, upper_bound: float) -> None:
    if reaction.lower_bound > upper_bound:
        reaction.lower_bound = upper_bound
    reaction.upper_bound = upper_bound

its fine and maybe its the most sensible

Anything else?

This is just an idea i had when I noticed that we were writing code like the above.

But using property overloads like this is pretty magic.
It might be too unexpected that changing one thing could result in multiple things changing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions