Consider having numbers.Real provide __complex__?

I've been following along various issues in mypy regarding challenges with getting the ABCs in numbers (https://docs.python.org/3/library/numbers.html) working. Currently, there's a lot of clever logic in the functions int, float, and complex. Currently, inheriting from Real doesn't give you __complex__. This is because the complex function doesn't need it—it falls back to __float__. I think it would be nice if it did for the purpose of type annotations. Best, Neil

Inheriting from `numbers.Real` _does_ give you `__complex__`, though: https://github.com/python/cpython/blob/314b8787e0c50985ba708034b84ff5b37a1d4... Is it instead `float.__complex__` you're asking for?

Yes, I believe the ask is for `int.__complex__`, `float.__complex__` and `complex.__complex__` ( https://github.com/python/mypy/issues/3186#issuecomment-762121456) On Mon, 18 Jan 2021 at 09:47, Mark Dickinson <mdickinson@enthought.com> wrote:
Inheriting from `numbers.Real` _does_ give you `__complex__`, though: https://github.com/python/cpython/blob/314b8787e0c50985ba708034b84ff5b37a1d4...
Is it instead `float.__complex__` you're asking for? _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/L7KA5V... Code of Conduct: http://python.org/psf/codeofconduct/

Thanks for the correction Mark, I didn't realize that! Shantanu is right about what my ask was meant to be. I guess I'm nowhere near the first to propose things like this and there's a lot of discussion in various threads about it that I wasn't aware of. Best, Neil On Monday, January 18, 2021 at 3:56:59 PM UTC-5 Shantanu Jain wrote:
Yes, I believe the ask is for `int.__complex__`, `float.__complex__` and `complex.__complex__` ( https://github.com/python/mypy/issues/3186#issuecomment-762121456)
On Mon, 18 Jan 2021 at 09:47, Mark Dickinson <mdick...@enthought.com> wrote:
Inheriting from `numbers.Real` _does_ give you `__complex__`, though: https://github.com/python/cpython/blob/314b8787e0c50985ba708034b84ff5b37a1d4...
Is it instead `float.__complex__` you're asking for? _______________________________________________ Python-ideas mailing list -- python...@python.org To unsubscribe send an email to python-id...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python...@python.org/message/L7KA5VUCJ... <https://mail.python.org/archives/list/python-ideas@python.org/message/L7KA5V...> Code of Conduct: http://python.org/psf/codeofconduct/
participants (3)
-
Mark Dickinson
-
Neil Girdhar
-
Shantanu Jain