Use duck-typing to check for non-numeric types in approx()#8136
Use duck-typing to check for non-numeric types in approx()#8136nicoddemus wants to merge 1 commit intopytest-dev:masterfrom
Conversation
| def __abs__(self) -> float: | ||
| return abs(self.value) | ||
|
|
||
| def __sub__(self, other): |
There was a problem hiding this comment.
I did try type-annotating the return value like this:
| def __sub__(self, other): | |
| def __sub__(self, other: Any) -> Union[float, "Container"]: |
However mypy complained with:
testing/python/approx.py:601:59: F821 undefined name 'Container'
testing/python/approx.py:608:60: F821 undefined name 'Container'
Is that because it is an inner class? Suggestions welcome. 👍
|
I think the Python number hierarchy is still useful in ApproxScalar, simply because anything that inherits from that hierarchy is guaranteed to be a scalar whose comparison methods return |
|
Closing in favor of #8137. |
Fix #8132