0

From line 54 in this example there is apparently something called a metaclass. I'm reading different code samples to check my understanding but have never seen this before.

Could someone explain what this "meta" code does exactly in this concrete example, or what the idea here is? In addition I see the use of with_metaclass that is just for Python 2/3 compatability (explained here). How would this code look like for Python 3? (In case all of this is just for compatability, etc)

Hills
  • 87
  • 1
  • 8
  • @Iguananaut From what I can read about metaclasses this is something "magical" unless you know exactly what you are doing. I would like to know the reason behind it's usage here in this concrete example, but - I see the post is now marked as a duplicate. I'll give you upvotes here though, if you would be so kind. – Hills Oct 24 '22 at 14:29
  • 1
    From a quick glance it looks here the metaclass is being used to create some kind of registry of subclasses, which is a very common use case for metaclasses. So common in fact that Python added an `__init_subclass__` hook that allows this kind of usecase without having to delve into metaclasses: https://stackoverflow.com/questions/45400284/understanding-init-subclass – Iguananaut Oct 26 '22 at 12:59

0 Answers0