Skip to content

Archive

Object Model

2 articles
Python 04 Sep 2026 8 min read

Use Slotted Dataclasses When Object Shape Is Fixed in Python

Python dataclasses reduce boilerplate for record-like classes, but their instances are still ordinary Python objects by default. Declared fields normally live in an instance dictionary, and new attributes can be attached later. That flexibility is useful until the model is supposed to have a fixed shape. Coordinates, parsed records, configuration snapshots, protocol messages, and other compact value objects often have a known set of fields. When many such objects exist, keeping dynamic per-instance attribute storage may also be unnecessary.

Python 02 Sep 2026 9 min read

Python Descriptors: Reusable Attribute Behavior Without Magic

Python properties are useful when one class needs a managed attribute. When the same attribute behavior must be reused across many fields or classes, repeating nearly identical properties becomes harder to maintain. Descriptors provide the protocol underneath properties, bound methods, classmethod, staticmethod, and other familiar Python features. A descriptor is an object stored on a class that can participate in reading, writing, or deleting an attribute. Descriptors are powerful because they integrate with normal dotted access such as obj.width. They are also easy to misuse if you do not understand where descriptor instances live, how values should be stored, and which lookup rules Python applies.