On Tue, Sep 1, 2020 at 11:21 AM Christopher Barker <pythonchb@gmail.com> wrote:
Thanks -- good to get this written down!

Question: it strikes me that the use case of [] for type hints is logically quite different than for indexing. So do they need to use the same syntax / dunder?

How would we differentiate what the caller means by the subscript invocation? 

Put another way: would the distinction be:

A) between 1. objects of the type `type` (class objects), and 2. non-type objects...?
B) between WHERE the innovation occurs in the code?

To explain further, A) looks like:

dict[ x, y ]

...calls:

dict.__type_subscript__( ( x, y ) )

...because dict is a class object, but:

d = dict(0
d[ x, y ]

...calls:

d.__getitem__( ( x, y ) )

...because d is not a class object?

Or B), so that for either of these:

d: dict[x, y]

...or this:

def f() -> dict[ x, y ]: ...

...the type checker calls (no effect at runtime):

dict.__type_subscript__( ( x, y ) )

...but this would still call __getitem__ at runtime:

class C: ...

>>> C[ x, y ]

...simply calls:

C.__getitem__(( x, y ))

...because the C[x,y] invocation occurs outside of a type hint location...?

B) at least seems like it isn't an option, since it's probably impossible to determine what things are type hints and what things aren't simply based on where they appear in code:

>>> MyType = C[x,y]  # this will be a type hint
>>> my_value = C[x,y]  # looking up a key on object C

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler