I find two different items named "value" in comparison functions confusing
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the Scalar comparison methods, including gt and eq, and review how their formal arguments are named. Rename the comparison operand consistently and make it positional-only as described; done means the confusing value.value references are removed without changing comparison behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100