Skip to content

Logic inconsistency in DoubleYAxis.good_colour() #50

@gb119

Description

@gb119

Description:

In src/stonerplots/context/double_y.py:157, the good_colour() method has potentially incorrect logic when self.colours is a string:

match self.colours:
    case list() if -len(self.colours) < axis < len(self.colours):
        return self.colours[axis] is not None
    case str() if -len(self.colours) < axis < len(self.colours):
        return True
    case _:
        return False

When self.colours is a string (e.g., "red"), len(self.colours) returns the string length (3 for "red"), not the number of colours (1). The condition -len(self.colours) < axis < len(self.colours) checks -3 < axis < 3, which may not be the intended behavior.

Questions to Clarify:

  1. Should a string colour apply to all axes?
  2. Should string length matter, or should it be treated as a single colour?
  3. Is the string case meant to handle comma-separated colours?

Suggested Fix (if string should apply to all axes):

def good_colour(self, axis: int) -> bool:
    """Return True if we have a colour defined for this axis."""
    axis = int(axis)
    if self.colours is None:
        return False
    match self.colours:
        case str():  # Single colour string applies to all axes
            return True
        case list() if -len(self.colours) < axis < len(self.colours):
            return self.colours[axis] is not None
        case _:
            return False

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-investogationIssue requires clarification or more details to understand fully

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions