[Python-Dev] Comments on PEP 560 (Core support for typing module and generic types) (original) (raw)
Ivan Levkivskyi levkivskyi at gmail.com
Sun Nov 19 17:36:51 EST 2017
- Previous message (by thread): [Python-Dev] Comments on PEP 560 (Core support for typing module and generic types)
- Next message (by thread): [Python-Dev] Comments on PEP 560 (Core support for typing module and generic types)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 19 November 2017 at 21:06, Mark Shannon <mark at 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 changingobject._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
_mroentries_
makes_classgetitem_
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_mroentries_
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
andissubclass
call_mroentries_
before raising an error if the second argument is not a class? In other words, ifList
implements_mroentries_
to returnlist
then shouldissubclass(x, List)
act likeissubclass(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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171119/f541fe1e/attachment.html>
- Previous message (by thread): [Python-Dev] Comments on PEP 560 (Core support for typing module and generic types)
- Next message (by thread): [Python-Dev] Comments on PEP 560 (Core support for typing module and generic types)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]