Skip to content

Conversation

@ilevkivskyi
Copy link
Member

Fixes#385
Fixes#384

In previous versions of typing, __bases__ on subscription where prepend with __origin__, so that MRO of, e.g., Mapping[int, T][str] was:

[Mapping[int, str], Mapping[int, T], Mapping, collections.abc.Mapping, ...]

This was removed for several reasons. However, now it looks like complete removal of such prepending was too radical, since now e.g. issublcass(Node[int], Node) returns False. I believe such runtime check should be equivalent to issublcass(Node, Node), i.e., True.

Here I propose to fix this by only prepending __bases__ on first subscription, so that, e.g, Mapping[int, T][str].__mro__ will be:

[Mapping[int, str], Mapping, collections.abc.Mapping, ...]

This PR also fixes an ambiguity when using typing ABCs with singledispatch().

@ilevkivskyiilevkivskyi changed the title Prepend basesPrepend bases on first subscriptionFeb 3, 2017
@ilevkivskyi
Copy link
MemberAuthor

This will also allow to simplify #375 to only adding tests. So that I would like to merge this now.
@gvanrossum I am mentioning you just in case, so that this will not pass unnoticed.

@ilevkivskyiilevkivskyi merged commit 1229efb into python:masterFeb 3, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

issubclass(Node[int], Node) returns False. singledispatch and typing.Tuple[x] interaction

2 participants

@ilevkivskyi@the-knights-who-say-ni