I realise this is late, and hence you've already likely answered this yourself.
Firstly, it seems that you misunderstand the kwds
argument of types.new_class
; it is the class keyword arguments, e.g
class MyMeta(type):
def __new__(metacls, name, bases, attrs, **config):
print(config)
return super().__new__(metacls, name, bases, attrs)
def __init__(cls, name, bases, attrs, **config):
super().__init__(name, bases, attrs)
class SomeCls(metaclass=MyMeta, debug=True):
pass
>> {'debug': True}
is analogous to (without the print)
SomeCls = types.new_class("SomeCls", (), {'debug':True})
These meta-arguments are useful when configuring meta-classes.
I am not really sure as to why new_class
was designed to accept a callable vs a dict directly, but I suspect it was to avoid implicit shared state between "new" classes that did not inherit from one another.