> Classes aren't a great abstraction when enforcing program invariants like "this object must at least have fields a and b."
Can you elaborate on the functional difference between
- an enhanced dictionary where certain keys are guaranteed as part of the type, and
- a record type (class, struct, whatever) with named fields?
Classes aren't a great abstraction when enforcing program invariants like "this object must at least have fields a and b." With a dict you can just have "dict(a=1, b=2, c=3)" and it works everywhere without serialization/deserialization and manual type conversions. Python's type checkers can't provide any safety for you if you do that, but that's a deficiency in the language, not the concept.