Conceptual
Login

Descriptors and the Property Decorator in Python

Descriptors are Python objects that implement `__get__`, `__set__`, and/or `__delete__` and are stored as class attributes; they intercept attribute access on instances, mediating between the instance and its stored state. A data descriptor (one defining `__set__`) takes precedence over an instance's `__dict__`, whereas a non-data descriptor (only `__get__`) can be shadowed by an instance attribute of the same name — this precedence rule governs Python's attribute lookup protocol. Descriptors underlie the built-in `property` mechanism and enable declarative, reusable field behavior (e.g., validation, computed/lazy values) without duplicating logic across classes, forming a core part of Python's object model and metaprogramming capabilities.