I was messing around with python metaclasses and I came across something very intriguing that I didn't know existed or was valid:
class Meta(type):
def __new__(metacls, name, bases, kwargs, extra_thing=None):
if extra_thing is not None:
print(extra_thing)
return super().__new__(metacls, name, bases, kwargs)
def __init__(metacls, name, bases, kwargs, *args, **kwargs_):
super().__init__(metacls, name, bases, kwargs)
class TestClass(metaclass=Meta, extra_thing='foo'):
pass
When you run this, 'foo' is printed.
So apparently, classes can have extra keyword arguments if their metaclasses allow for it.
If a scenario in which this functionality may be useful is found, is it okay to take advantage of it? Or should it be left alone in favour of other methods (such as defining a class wide variable extra_thing)?