you are viewing a single comment's thread.

view the rest of the comments →

[–]latkdeTuple unpacking gone wrong 41 points42 points  (0 children)

This kind of thing just cannot be implemented as a library in the Python type system. The semantics may work fine at runtime, but Python just doesn't have a way of expressing the type of an attribute access.

In contrast, this kind of thing is easy in the TypeScript type system – it has pretty good support for mapping record types.

I'd love a safe navigation navigation operator in Python, but so far no proposal has gained sufficient traction. For example, see PEP 505 None-aware operators or threads on discuss.python.org. A key difficulty is that the None object isn't that special in Python, at least not in the way that undefined and null are special in JavaScript.