[issue24234] Should we define complex.__complex__ and bytes.__bytes__?

Mark Dickinson report at bugs.python.org
Mon Aug 23 06:05:09 EDT 2021


Mark Dickinson <dickinsm at gmail.com> added the comment:

> If SupportsComplex and SupportsBytes are just for "has __complex__/__bytes__ method", they are virtually useless.

I agree that "SupportsComplex" isn't directly useful in user-land. I think its main value is as a building block in things like `Union[SupportsComplex, SupportsFloat, SupportsIndex]`.

For me, the gain from implementing complex.__complex__ is that the test "can be used as a complex number" can now be expressed purely in terms of the protocols offered, without reference to concrete types.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue24234>
_______________________________________


More information about the Python-bugs-list mailing list