Mark Dickinson <dicki...@gmail.com> added the comment:
> [...] we'll need `int.__complex__` and `float.__complex__` implementations as > well as `complex.__complex__`. The real problem here is that the "typing.SupportsComplex" protocol isn't a good match for code that needs to know that a given value `x` can be treated as though it were a complex number. The test that best matches "usable as a complex number" seems to be that type(x) implements at least one of `__index__`, `__float__` or `__complex__`, or that `x` is a subclass of complex. It looks to me as though the right thing to do here is to just implement complex.__complex__, but not int.__complex__ or float.__complex__. Then at least we can remove the subclass test from the above and express the test purely in terms of special methods: __index__, __float__ and __complex__. And then perhaps it's for the typing module to find a more convenient way to express the union of typing.SupportsIndex, typing.SupportsFloat and typing.SupportsComplex. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue24234> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com