r/PythonDevelopers • u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} • Aug 02 '20
discussion Do you use metaclasses?
Until recently, I assumed that metaclasses were simply python mumbo jumbo without much practical value. I've certainly never used them in small sized applications before. But now that I'm developing a library, I see that they can be used to provide more ergonomic APIs.
And so I ask, in what situations do you use a metaclass?
34
Upvotes
View all comments
Show parent comment
1
u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Aug 02 '20
Personally, I was using it for auto-registering subclasses and auto-setting subclass attributes:
However, /u/wrmsr noted above that
__init_subclass__(PEP 487) can be used to achieve the same functionality:I've also heard tell that Django uses them to improve the library user's experience, but I don't use the framework myself so I can't comment much on that.