-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Revert "Let SupportsDunderLT return SupportsBool instead of `bool…
#14373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…`. (python#12939)" This reverts commit aed8025.
|
Diff from mypy_primer, showing the effect of this PR on open source code: colour (https://github.com/colour-science/colour)
+ colour/plotting/colorimetry.py:565: error: Value of type variable "SupportsRichComparisonT" of "min" cannot be "floating[_16Bit] | floating[_32Bit] | float64" [type-var]
+ colour/plotting/colorimetry.py:566: error: Value of type variable "SupportsRichComparisonT" of "max" cannot be "floating[_16Bit] | floating[_32Bit] | float64" [type-var]
jax (https://github.com/google/jax)
- jax/_src/pallas/mosaic/pipeline.py:1546: error: Unused "type: ignore" comment [unused-ignore]
ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/types/relations.py:2986: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "NumericValue | float" [type-var]
arviz (https://github.com/arviz-devs/arviz)
+ arviz/stats/ecdf_utils.py:72: error: Value of type variable "SupportsRichComparisonT" of "min" cannot be "Any | float64" [type-var]
|
It isn't though: from typing import Protocol, final
@final
class NotTruthy:
__bool__ = None
class SupportsBool(Protocol):
def __bool__(self, /) -> bool: ...
x: SupportsBool = NotTruthy() # rejected |
|
@jorenham I don't think that's currently an officially supported pattern – opposed to |
|
The official data model states:
See also https://mail.python.org/archives/list/[email protected]/thread/YGAK34DRWJFSIV2VZ4NC2J24XO37GCMM/ |
Ok fair enough. But then what about the fact that Lines 106 to 139 in 213e696
>>> object.__bool__
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
object.__bool__
AttributeError: type object 'object' has no attribute '__bool__'. Did you mean: '__doc__'? |
|
Ok, makes sense to me. So let's re-apply the original PR and start using |
That should only be needed if a base class implements from typing import Protocol
class SupportsBool(Protocol):
def __bool__(self, /) -> bool: ...
x: SupportsBool = object() # rejected |
As @JelleZijlstra pointed out, this is basically equivalent to returning
object(since all objects implement__bool__). So I'm reverting this.