DEV Community

Cover image for Mastering Metaclasses in Python using real-life scenarios

Mastering Metaclasses in Python using real-life scenarios

Muhammad Ihsan on January 04, 2024

Metaclasses in Python offer a powerful way to shape how classes are defined, providing developers with the means to enforce coding standards, limit...
Collapse
 
jnussbaum profile image
Johannes Nussbaum

Hi Muhammad,
Thanks for your article, I like it a lot :-)
I think I spotted a mistake: In the very first code example, there is a def __new__() that calls super().__new__(), and then there is a def __call__() that also calls super().__new__(). Is that correct? Shouldn't it call super().__call__()?

Collapse
 
iihsan profile image
Muhammad Ihsan

Yes, you're right, I just corrected it. Thanks for your valuable feedback

Collapse
 
vlc33 profile image
VLC33

It's good to see a working examples for metaclasses, usually explanations about metaclasses started something with "You don't need to use metaclasses, find other way around".

Collapse
 
iihsan profile image
Muhammad Ihsan

Thanks for appreciating my content, it's my first article on dev.to ever, and this really boosted my energy, and now I am trying my best to share more such content. Thanks

Collapse
 
wlagyorgy profile image
wlagyorgy

Great job! It was a pleasure to read. Maybe if you add some explanation for the arguments of the metaclass' methods, even beginners could understand it fully.

Collapse
 
iihsan profile image
Muhammad Ihsan

Thanks for your positive feedback, let me edit it and add more explanations.

Collapse
 
iihsan profile image
Muhammad Ihsan

Hi @wlagyorgy, I just added more explanation for methods and their arguments. Kindly check the article now.
For your reference: I have made changes in the Understanding Metaclasses body.

Collapse
 
wlagyorgy profile image
wlagyorgy

Gorgeous! Thanks!

Collapse
 
ktreharrison profile image
Ken Harrison

Great article!

Collapse
 
iihsan profile image
Muhammad Ihsan

Thanks for your appreciation!

Collapse
 
revisto profile image
Alireza Shabani

Great article, thanks.

Collapse
 
iihsan profile image
Muhammad Ihsan

Thanks for your appreciation.

Collapse
 
maiobarbero profile image
Matteo Barbero

Thanks for your article!

Collapse
 
iihsan profile image
Muhammad Ihsan

Thanks for your appreciation.

Collapse
 
hasii2011 profile image
Humberto A Sanchez II

Nice lucid explanation. I'll keep this in my back pocket

Collapse
 
iihsan profile image
Muhammad Ihsan

Thanks for boosting my energy, a lot much content is on the way...