Skip to content

I find two different items named "value" in comparison functions confusing #230

@KostaIlic2

Description

@KostaIlic2

Tech Debt

We have value as a data member and value as a formal argument. Very different use, but identical names.

I will illustrate the problem with one of the functions:

def __gt__(self, value: Scalar[TScalar_co]) -> bool:
    """Return self > value."""
    if not isinstance(value, self.__class__):
        return NotImplemented
    self._check_units_equal_for_comparison(value.units)
    if isinstance(self.value, _NUMERIC) and isinstance(value.value, _NUMERIC):
        return self.value > value.value  # type: ignore[no-any-return,operator]  # https://github.c
    elif isinstance(self.value, str) and isinstance(value.value, str):
        return self.value > value.value
    else:
        raise TypeError("Comparing Scalar objects of numeric and string types is not permitted")

Several places where we have the value.value construct are particularly confusing.

I suggest changing the name of the formal argument to "other", and adding a slash the way we have it in eq to make sure that other is treated as positional argument only.

AB#3603272

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech debtNon-user-visible improvement to code or development process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions