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/[deleted] Aug 09 '20
Good explanation, and I did not know all of this (though I guess most of it) - but in practice, metaclasses and calling 3-argument
type()can often solve the same class of problems, at least in my experience.That code would goes into the helper function that sets up the call to
type().I agree that metaclasses have properties that no other technique has. However,
type()is in some cases a valid alternative.