On Tue, Apr 20, 2021 at 10:07 AM Mark Shannon <mark@hotpy.org> wrote:
Hi everyone,
Once upon a time Python was a purely duck typed language.
Then came along abstract based classes, and some nominal typing starting to creep into the language.
If you guarded your code with `isinstance(foo, Sequence)` then I could not use it with my `Foo` even if my `Foo` quacked like a sequence. I was forced to use nominal typing; inheriting from Sequence, or explicitly registering as a Sequence.
You say this like it's a bad thing, but how is this avoidable, even in principle? Structural typing lets you check whether Foo is duck-shaped -- has appropriate attribute names, etc. But quacking like a duck is harder: you also have to implement the Sequence behavioral contract, and realistically the only way to know that is if the author of Foo tells you. I'm not even sure that this *is* nominal typing. You could just as well argue that "the operation `isinstance(..., Sequence)` returns `True`" is just another of the behavioral constraints that are required to quack like a sequence. -n -- Nathaniel J. Smith -- https://vorpus.org