4 ms·
`singledispatchmethod` definitely looks useful. The name isn't great, though. It actually offers double dispatch, not single dispatch! `divider.divide(10, 2)`
by tonyg 4y ago
`singledispatchmethod` definitely looks useful.
The name isn't great, though. It actually offers double dispatch, not single dispatch! `divider.divide(10, 2)` first dispatches on `divider`, then on `10`.
As so often with Python, I'm left wondering why they didn't follow through and properly complete the design, in this case perhaps offering multiple dispatch (multimethods) instead of just double dispatch. Casting an eye over the functools code, it looks like they have all the necessary C3 infrastructure in there.
- formerly_proven 4y agoPython sort of has multimethods, but only for type-annotations, not for actually dispatching to code.
- isoprophlex 4y agoDefinitely useful. That code looks ugly as fuck though
- make3 4y agothis feels really unpythonic, would be very surprised if I saw this in code