I have a metaclass that takes keyword arguments:
class M(type): def __new__(cls, *args, **kwargs): print(*kwargs.items()) super().__new__(cls, *args)
It works as expected:
class A(metaclass=M, test='X'): pass
leads to object A and printout
('test', 'X')
I would like to make a copy of A using something like this :
def copy_class(cls, name=None): if name is None: name = cls.__name__ return type(cls)(name, cls.__bases__, dict(cls.__dict__)) A_copy = copy_class(A, 'A_copy')
However, there are no keywords. This is especially a problem when type(cls) requires additional arguments or otherwise creates different side effects when they are not there.
I know that I can have M put keywords in a class object somewhere, but this is not a very good solution, because then my copy method is very dependent on the class.
Is there a built-in way to get the keywords that the class created in Python?
source share