Skip to content

Recent change to MROs of built-in types caused Python 2/3 inconsistency #2655

Closed

Description

@JukkaL

#2602 caused this to behave differently in mypy Python 2 and 3 modes:

reveal_type(['a', {'b'}])

In Python 2 mode it shows this:

Revealed type is 'builtins.list[typing.Sized*]'

In Python 3 mode it shows this:

Revealed type is 'builtins.list[typing.Collection*[builtins.str]]'

Before the PR Python 2 behavior was closer to Python 3:

Revealed type is 'builtins.list[typing.Iterable*[builtins.str]]'

This change causes regressions for mypy users, since the old type was more precise. More generally, any change in the MROs of built-in types has a significant chance of generating regressions and should be tested carefully.

Not sure what's the best way to move forward. I'd prefer getting Python 2 and Python 3 to be more similar if possible. Maybe we don't need to include Sized explicitly in the MRO since it's a protocol? Again, this could have unforeseen results.

cc @gvanrossum

Activity

  1. srittau commented on Nov 30, 2018

    @srittau
    Collaborator

    I'm generally in favor of not including protocols in base classes, although in this case it makes some sense, since Sequence is part of the basic type hierarchy. For now I suggest to revert this change until mypy 0.650 is released and discuss this afterwards (and live with the results of that discussion).

  2. added a commit that references this issue on Nov 30, 2018
    2357959
  3. added a commit that references this issue on Nov 30, 2018
    eaeb5fc
  4. added 2 commits that reference this issue on Nov 30, 2018
  5. added a commit that references this issue on Nov 30, 2018
    0e3750e
  6. gvanrossum commented on Nov 30, 2018

    @gvanrossum
    Member

    Reopening because I want a different fix (see #2658).

  7. added a commit that references this issue on Nov 30, 2018
    de50614
  8. added 2 commits that reference this issue on Jan 23, 2019
    a6fb268
    dfc83de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions