Revisiting PEP 505

I personally prefer accessing items via dot notation over subscript so I use the wrapper from dict2dot · PyPI to access dict keys as attributes. Although you are right that a predefined validation schema is the right thing to do for the long term we often don’t do that for smaller projects just to get things working quickly.

CPython itself also has a data model where certain attributes are optional for some data types due to dynamic initializers, duck typing or backwards compatibility. Below are a few examples that can benefit from Guido’s generalization:

And here are the dozens of other instances of getattr(obj, "attr", None) in CPython where certain attributes are optional in the data model.

5 Likes