top | item 23717287

(no title)

mar77i | 5 years 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)

discuss

order

heavenlyblue|5 years ago

Have you read the RFC before posting this?

There’s a magic method called “match” that you can override to support matching.