|
|
|
|
|
by mar77i
2176 days ago
|
|
I wonder why anyone would think inverting semantics like this was anything but asking for disaster. With all the metaprogramming that is possible, will the matching Cat(age=age) even produce a coherent object that has an age argument passed to __init__? Do keyword arguments in those patterns work on properties? How will it compare to another cat, is that using "is" or __eq__? Does Cat have to derive from the same type object? def Cat(**kwargs):
return type("Cat", (), {"__init__": lambda self, **kw: ([setattr(self, k, v) for k, v in kw.items()], None)[-1]})(**kwargs)
|
|
There’s a magic method called “match” that you can override to support matching.