Skip to content

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

@JukkaL

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

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