Overview
Metaclasses¶
- Understanding Python Classes
- Dynamic Class Creation
- More Accurate Dynamic Class Creation
- Metaclasses in Python
- Run Methods Order in Python
- Run Methods Order in Python with More Explanation
- Invisible Metaclasses in Python
- Meta Classes without type
- More Accurate Meta Classes without type
Examples¶
- Register Classes in Python
- Singleton in Python
- Auto Slots
- Logging Namespace
- Modeling a Class with a Metaclass
- Define Method If Condition True
Example on CPython
>>> import enum
>>> enum.Enum
>>> import abc
>>> abc.ABC
>>> import typing
>>> typing.Any
Example on 3.party libs
- https://github.com/django/django/blob/main/django/db/models/base.py#L92
- https://github.com/pydantic/pydantic/blob/main/pydantic/main.py#L47
Tutorial, Docs, Videos¶
- https://www.youtube.com/watch?v=yWzMiaqnpkI
- https://realpython.com/python-metaclasses/
- https://www.python.org/doc/essays/metaclasses/
- https://docs.python.org/3/reference/datamodel.html#customizing-class-creation
- https://peps.python.org/pep-3115/
- https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python
- https://jfreeman.dev/blog/2020/12/07/python-metaclasses/
- https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/
- https://jfreeman.dev/blog/2020/12/07/python-metaclasses/
- https://peps.python.org/pep-3115/
CPython Implementation¶
Last update: June 2, 2023
Created: June 2, 2023
Created: June 2, 2023