> Hmm... OK, that's an interesting desire.  How do square brackets get you
any closer to that?

I use `__class_getitem__` as a memoized type factory that builds a new
subtype when it's called or returns the cached type.

You are correct I could name it as something else, there is nothing special
about the square brackets other than notation but having a visual
distinction of type creation and instantiation is useful.

On Sat, Aug 15, 2020 at 3:44 PM David Mertz <me...@gnosis.cx> wrote:

> On Sat, Aug 15, 2020 at 4:38 PM Caleb Donovick <donov...@cs.stanford.edu>
> 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?
>
>
> --
> The dead increasingly dominate and strangle both the living and the
> not-yet born.  Vampiric capital and undead corporate persons abuse
> the lives and control the thoughts of homo faber. Ideas, once born,
> become abortifacients against new conceptions.
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NQXZKISQQ6DJM4IOZGURB62G32DBWMCM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to