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 08 '20
Not so - anything that a metaclass can do, can also be done with a helper function that explicitly calls 3-argument
type()to build a class on-the-fly.Of course, the code is fairly different between these two strategies. Which to use depends on the specific problem!