(original) (raw)

On 19 November 2017 at 21:06, Mark Shannon <mark@hotpy.org> wrote:
By far and away the largest change in PEP 560 is the change to the behaviour of object.\_\_getitem\_\_. This is not mentioned in the PEP at all, but is explicit in the draft implementation.
The implementation could implement \`type.\_\_getitem\_\_\` instead of changing \`object.\_\_getitem\_\_\`, but that is still a major change to the language.

Except that there is no such thing as object.\_getitem\_\_. Probably you mean PyObject\_GetItem (which is just what is done by BINARY\_SUBSCR opcode).
In fact, I initially implemented type.\_\_getitem\_\_, but I didn't like it for various reasons.

I don't think that any of the above are changes to the language. These are rather implementation details. The only unusual thing is that while dunders are
searched on class, \_\_class\_getitem\_\_ is searched on the object (class object in this case) itself. But this is clearly explained in the PEP.
In fact, the addition of \`\_\_mro\_entries\_\_\` makes \`\_\_class\_getitem\_\_\` unnecessary.

But how would you implement this:

class C(Generic\[T\]):
...

C\[int\] # This should work

The name \`\_\_mro\_entries\_\_\` suggests that this method is solely related method resolution order, but it is really about providing an instance of \`type\` where one is expected. This is analogous to \`\_\_int\_\_\`, \`\_\_float\_\_\` and \`\_\_index\_\_\` which provide an int, float and int respectively.
This rather suggests (to me at least) the name \`\_\_type\_\_\` instead of \`\_\_mro\_entries\_\_\`

This was already discussed during months, and in particular the name \_\_type\_\_ was not liked by ... you https://github.com/python/typing/issues/432#issuecomment-304070379
So I would propose to stop bikesheding this (also Guido seems to like the currently proposed name).

Should \`isinstance\` and \`issubclass\` call \`\_\_mro\_entries\_\_\` before raising an error if the second argument is not a class?
In other words, if \`List\` implements \`\_\_mro\_entries\_\_\` to return \`list\` then should \`issubclass(x, List)\` act like \`issubclass(x, list)\`?
(IMO, it shouldn't) The reasoning behind this decision should be made explicit in the PEP.

I think this is orthogonal to the PEP. There are many situations where a class is expected,
and IMO it is clear that all that are not mentioned in the PEP stay unchanged.

--
Ivan