On Sat, Aug 15, 2020 at 4:38 PM Caleb Donovick email@example.com wrote:
Why would it require a metaclass? Rather than just: ...
Because I want the following to be true: x = Struct[x=int, y=str](...) assert isinstance(x, Struct) assert isinstance(x, Struct[x=int, y=str]) assert not isinstance(x, Struct[x=int, y=int])
Hmm... OK, that's an interesting desire. How do square brackets get you any closer to that?
If this proposal, in whatever variation, is adopted, `Struct[x=int, y=str]` is going to be some kind of call to .__getitem__(). There is some debate about exactly how the information gets passed into the method, but we can bracket that for this question. One way or another, positional and named arguments are available to this future .__getitem__().
So how do you make this true:
assert isinstance(x, Struct.__getitem__(x=int, y=str)) assert not isinstance(x, Struct.__getitem__(x=int, y=int))
For demonstration, maybe it's easiest just to give a new name to the hypothetical method. Say `Struct.bracket(...)`. It's not obvious to me how you'll get the behavior you want.
... and if you CAN get the behavior, why can't we name this method .__call__()?
I'm not really sure what kind of thing Struct is meant to be, as well. Is it a class? An instance? A class factory? A metaclass?