The issue with this and `singledispatch` is that they no longer support pseudo-types from the `typing` module [1] so you can't use them with containers of type `x`, e.g. `List[str]`, or protocols like `Sequence`.
Yea, this one is really annoying... required a lot of rewriting of code to make some old code work with 3.7.
I don't understand why anyone would want singledispatch. Instead of having the function defined in one place where you can look it up, now the function is potentially scattered all over the place. (I'm not talking hypothetically. I've had the 'pleasure' of working on a codebase where different singledispatch cases of the same function were defined in different files!)
Re:What’s New in Python 3.8
by CreRecombinase on Tuesday October 15, 2019 @09:57AM
(#21258359)
Because if you need to branch based on type more than a few times in your function it can get pretty hard to read. Am I right that the basis of your complaint is that it's now harder to find all the members of (what you'd call in C++) the "overload set" for a particular function? If so I can see your point.
Yes, that's my point. And it doesn't really simplify the function itself, it just rearranges it, in the same way you can break up a complex painting into jigsaw pieces and say, "Look, each piece is simple!"
Re:What’s New in Python 3.8
by CreRecombinase on Tuesday October 15, 2019 @12:54PM
(#21260659)
I think the answer to the question "should I apply X refactoring technique to this function Y?" obviously has to depend on both X and Y. There's clearly a trade-off here. If I have a free function foo(x) that I want to work differently depending if x is type A or type B, splitting that means breaking up foo, sure, but because I can only ever call foo with an x of type A or type B (unless I'm converting some As to Bs halfway through foo or something awful like that) it might be useful to see all of the "A" logic in one place and all of the "B" logic in another place.
I can definitely imagine some places where this replaces type-checking, but it still seems like a bit of an unfortunate anti-pattern to me, since it's really a sort of C/C++ style function prototype match.
My immediate thought is that it's going to be hard for PyCharm to reliably point me to a function definition.
Re:What’s New in Python 3.8
by heavenlyblue on Tuesday October 15, 2019 @06:50AM
(#21257246)
>> My immediate thought is that it's going to be hard for PyCharm to reliably point me to a function definition.
I am certain PyCharm is going to special-case these decorators in their next release.
Nice. I missed this feature only a few weeks ago. Good to know it's landed!
Few years ago I wrote this thing: https://github.com/adh/py-clos
It can also do dispatch on multiple arguments and on equality and has dispatch cache implemented as C extension (from my rudimentary measurements it seems that dispatch with cache hit is actually slightly faster than normal CPython method call).
[1] https://docs.python.org/3/library/functools.html#functools.s...
[2] https://docs.python.org/3/library/functools.html#functools.s...