How To Keep Track Of Keywords Passed To Metaclass?
I have a metaclass that accepts keyword arguments: class M(type): def __new__(cls, *args, **kwargs): print(*kwargs.items()) super().__new__(cls, *args) It work
Solution 1:
Python will not save the keyword arguments for you. This is simple to demonstrate:
>>>classDoesntSaveKeywords(type):...def__new__(cls, name, bases, dict, **kwargs):...returnsuper().__new__(cls, name, bases, dict)...>>>classPrintsOnDel:...def__del__(self):...print('__del__')...>>>classFoo(metaclass=DoesntSaveKeywords, keyword=PrintsOnDel()):...pass...
__del__
Also, I don't think the underlying idea of trying to copy a class like this makes sense. There's no guarantee that the class's __dict__
looks anything like what was originally passed to the metaclass constructor, or that calling the metaclass constructor again will do anything remotely reasonable.
Post a Comment for "How To Keep Track Of Keywords Passed To Metaclass?"