How is __metaclass__ used in real life.
Vimarsh Chaturvedi (~vimarsh) |
30
Description:
Class objects in python are themselves instances of the type class. Usage of the metaclass allows you to modify the process of creating a class object. Practical use-cases use metaclass attribute to add, delete, rename, or substitute methods and attributes in the class that is initiated.
Content:
Theory
- Class objects are instances of
typeclass - How to override the
typeclass - Introduction to the
__prepare__method
Examples
- How to create singleton classes in Python
- Using
metaclassto introduce methods in a class without inheritance - How
metaclassis used in Django REST Framework Serializers. - How Django uses
metaclassto maintain backward compatibility
Prerequisites:
- Intermediate familiarity object oriented programming concepts and how inheritance works in Python
- Basic understanding of serializers (Not compulsory).
Speaker Info:
Vimarsh Chaturvedi is currently working at Hedgehog labs as Developer. Graduated from Delhi Technological University in 2016. Lover of Python and small time contributor to Django REST Framework. In his spare time he likes to get into the nuts and bolts of Django and Django REST Framework. Likes to override DRF functionalities and write mixins on steroids for fun. Firm believer of if you have to write the same code twice there is a more elegant way to do it.