Browse by Topic

Popular

Latest

Latest Python Posts

Diagram of metaclass __new__ creating a class object from a class body
Python

Python __new__ Metaclass: Class Creation Explained

Understand how __new__ in a metaclass controls class creation, how it differs from __init__, and when to use it for class customization.

metaclass__new__class creationmetaprogramming
An illustration of a Python class definition passing through a custom metaclass before becoming a class object, showing the interception step.
Python

Python Custom Metaclass: How to Write and Use One

Learn how to write a custom metaclass in Python: syntax, practical examples, common pitfalls, and when to prefer simpler tools like __init_subclass__.

metaclasspythonclass-creationoop
Diagram showing a class object being created by the type metaclass, with a custom metaclass subclassing type in the background.
Python

Python Type Metaclass: How Classes Are Created

How Python's type metaclass creates classes, how to subclass type for custom metaclasses, and when the __init_subclass__ hook is the lighter alternative.

pythonmetaclassestypeclass creation
Diagram showing a metaclass controlling the creation of a class object in Python.
Python

Python Metaclass Basics: Controlling Class Creation

python metaclass basics: Understand Python metaclasses: what they are, how they control class creation, and when to use them for practical code generation and validation.

metaclassmetaprogrammingclass creationpython internals
A diagram showing a class being created by a metaclass, with type as the default metaclass.
Python

Python Metaclass: Controlling Class Creation

How Python metaclasses control class creation, when they are useful, and how they differ from class decorators.

metaclasspythonclass creationtype
Illustration of a Python descriptor object receiving its attribute name during class creation.
Python

How Python's __set_name__ Works in Descriptors

Learn how Python's __set_name__ descriptor method captures the attribute name during class creation, enabling self-aware validators and ORM fields.

descriptorsPython classesPEP 487attribute binding
Illustration of a Python custom descriptor controlling attribute access between a class and an instance.
Python

Python Custom Descriptor: Controlling Attribute Access

Learn how to build a python custom descriptor to control attribute access, validate values, and reuse logic across classes with the descriptor protocol.

descriptorspythonmetaprogrammingattribute access
Illustration comparing Python descriptor protocol and property decorator for attribute access.
Python

Python Descriptor vs Property: Choosing the Right Attribute Mechanism

Compare Python descriptors and property: how they work, when to use each, and how property is built on the descriptor protocol.

PythonDescriptorsPropertyAttribute Access
Illustration of Python attribute lookup precedence showing a non-data descriptor and instance dictionary
Python

Python Non-Data Descriptors: How They Work and When to Use Them

Understand Python non-data descriptors, how they differ from data descriptors in attribute lookup, and when to use them with practical code examples.

Pythondescriptorsmetaprogrammingattribute access
Diagram showing a Python data descriptor with __get__ and __set__ methods controlling attribute access between a class and an instance.
Python

Python Data Descriptors: How They Work and When to Use

Learn how Python data descriptors work, how they differ from non-data descriptors, and when to use them for validation, caching, and cleaner attribute access.

descriptorspythonattribute accessmagic methods