<story><title>Metaprogramming in Python</title><url>https://developer.ibm.com/tutorials/ba-metaprogramming-python/</url></story><parent_chain></parent_chain><comment><author>samwillis</author><text>This oft-repeated quote is always relevant on Python metaclass posts:&lt;p&gt;“[Metaclasses] are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don’t (the people who actually need them know with certainty that they need them, and don’t need an explanation about why).”&lt;p&gt;&lt;i&gt;Tim Peters, Inventor of the timsort algorithm and prolific Python contributor&lt;/i&gt;&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.oreilly.com&amp;#x2F;library&amp;#x2F;view&amp;#x2F;fluent-python&amp;#x2F;9781491946237&amp;#x2F;ch21.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.oreilly.com&amp;#x2F;library&amp;#x2F;view&amp;#x2F;fluent-python&amp;#x2F;978149194...&lt;/a&gt;&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;en.m.wikipedia.org&amp;#x2F;wiki&amp;#x2F;Tim_Peters_(software_engineer)&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;en.m.wikipedia.org&amp;#x2F;wiki&amp;#x2F;Tim_Peters_(software_enginee...&lt;/a&gt;&lt;p&gt;I would then also concur with the other comment that if you “know” you need metaclasses, 99% of the time actually you only need __subclass_init__.&lt;p&gt;A lot of online literature about Python meta programming misses out __subclass_init__ as it was only added to Python 3.6 in 2015 via PEP 487.&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;peps.python.org&amp;#x2F;pep-0487&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;peps.python.org&amp;#x2F;pep-0487&amp;#x2F;&lt;/a&gt;</text></comment>
<story><title>Metaprogramming in Python</title><url>https://developer.ibm.com/tutorials/ba-metaprogramming-python/</url></story><parent_chain></parent_chain><comment><author>kkirsche</author><text>Thanks for sharing! Instead of using meta classes for subclass registration though, please just use __subclass_init__ instead. It’ll often be simpler unless you have a complex use case.&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;docs.python.org&amp;#x2F;3&amp;#x2F;reference&amp;#x2F;datamodel.html#object.__init_subclass__&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;docs.python.org&amp;#x2F;3&amp;#x2F;reference&amp;#x2F;datamodel.html#object.__...&lt;/a&gt;</text></comment>