Multiple Dispatch for Binary Operators in Python
![](https://secure.gravatar.com/avatar/0f393da4b8265592816178e5ff6c1c62.jpg?s=120&d=mm&r=g)
Hi everyone, My friend and I have been interested in multiple dispatch for a while, and we noticed that it might be worth considering using it to resolve some fundamental difficulties type-checkers have understanding binary operators. We wrote up a collab summarizing our ideas: https://colab.research.google.com/drive/1-HQa5GOmV-uhTbv6EgnMfJYVgwuYMIrQ#sc... I initially posted a short version of this idea to python-ideas, but Guido suggested I flesh out the idea and post it here. Looking forward to everyone's insight and comments, Best, Neil
![](https://secure.gravatar.com/avatar/5dc484e83f87a994a4c21c21e8b9c1b0.jpg?s=120&d=mm&r=g)
Awesome idea! I wrote a typed single-dispatch some time ago: https://github.com/dry-python/classes Maybe it would be helpful to you. The biggest problem I had was generics support. For example, what would happen in case of: ```python from numbers import Real, Integral @dispatch() def __lt__(lhs: list[Real], rhs: list[Real]) -> bool: ... ``` I had troubles with it. And my version does not support generics with type arguments (because that's how isinstance works which we rely on during runtime). The second problem is protocols (generic protocols are the hardest). What should happen in a case of: ```python @dispatch() def __lt__(lhs: int, rhs: int) -> bool: ... @dispatch() def __lt__(lhs: SupportsInt, rhs: SupportsInt) -> bool: ... ``` Should it be dependent on the order of declarations? Or should we check the most specific types first? How to determine the most specific types? This is really a deep topic! Best, Nikita Sobolev https://github.com/sobolevn чт, 29 окт. 2020 г. в 00:43, Neil Girdhar <mistersheik@gmail.com>:
Hi everyone,
My friend and I have been interested in multiple dispatch for a while, and we noticed that it might be worth considering using it to resolve some fundamental difficulties type-checkers have understanding binary operators. We wrote up a collab summarizing our ideas: https://colab.research.google.com/drive/1-HQa5GOmV-uhTbv6EgnMfJYVgwuYMIrQ#sc...
I initially posted a short version of this idea to python-ideas, but Guido suggested I flesh out the idea and post it here. Looking forward to everyone's insight and comments,
Best,
Neil _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: n.a.sobolev@gmail.com
participants (2)
-
Neil Girdhar
-
Никита Соболев