Re:Show HN: I Wrote a Book on Java
by maleldil on Tuesday September 24, 2024 @04:39PM
(#41640677)
That needs to be explicit for any interacting types. You must define separate classes and explicitly define their hierarchy. This is fine if you control all the types, but it breaks down quickly. The best example is having two TypedDicts with the same members; in Python, you cannot use one instead of the other.
On the other hand, this is legal in Typescript:
This is most useful when A has a subset of B's attributes, like this (which also doesn't work in Python):
[ Parent
| on HN ]
That seems a lot like duck typing to me.
Yes, it is. Typed Python supports duck typing to some extent; see typing.Protocol and stuff like Sequence, Iterable, Mapping, etc.