5 ms·
> But having to do it everywhere? Ugh. I don't think people realise how powerful duck typing is for doing polymorphic code. Duck typing is indeed powerful, but
by gpderetta 2y ago
> But having to do it everywhere? Ugh. I don't think people realise how powerful duck typing is for doing polymorphic code.
Duck typing is indeed powerful, but it does not need to be a runtime check.
> What am I going to do, define an ABC or typing.Protocol called `ListLike` or something?
Yes, how am I going to know what types I can pass to mean instead? I would go to the extreme of saying that a lot of python code should be type annotated (if annotated at all) with protocols instead of concrete or base classes.
Of course until type checking is properly integrated in the interpreter this is all kind of pointless.
- globular-toast 2y ago> Yes, how am I going to know what types I can pass to mean instead? Oh, if I'm writing it for you (ie. I'm writing a library) then I'll put documentation (probably as type annotations, as I said in the first half of my comment). But a lot of code I write is just for me, or is going to be part of a completely self-contained project and it would be obvious from context what to pass. Like I said, it's a judgement call that Python expects you to be able to make.