Skip to content

Protocols are too "eager" to match an overload #3656

Closed
@ilevkivskyi

Description

@ilevkivskyi

This is a follow-up for #3132 (this does not happen on master).

Consider this example found by @JukkaL in #3132:

from typing import Mapping, Any
import sqlite3

class dict_like_row(sqlite3.Row, Mapping[str, Any]):
    def f(self) -> None:
        d = dict(self)  # Need type annotation for variable   <--- wasn't required before

It looks like this problem appears because sqlite3.Row has an untyped __iter__ and it is therefore considered a subtype of Iterable protocol and therefore matches another overload of dict constructor (annotating Row.__iter__ fixes the problem).

It is not clear what is the right way here, maybe we can somehow tweak overload similarity in case of an unsuccessful inference (here e.g. Tuple[KT, VT] never matches Any).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions