You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportMapping, Anyimportsqlite3classdict_like_row(sqlite3.Row, Mapping[str, Any]):
deff(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).
The text was updated successfully, but these errors were encountered:
@ilevkivskyi -- I wasn't able to reproduce the error on master (using both sqlite3's Row and a custom Row class w/ an untyped __iter__ method). Maybe this was fixed? It's also entirely possible that I'm not understanding the example (protocols are black magic to me tbh).
Can you check and see if this is still an issue whenever you have time?
before protocols, the class in example only matched the first overload, but after Iterable became structural, the class is also a structural subtype of Iterable[Any], so it matches the second one too. Moreover, it was matched preferably, because IIRC structural matches were given higher similarity for other reasons. Then type inference failed when trying to find any constraints on variables from Any <: Tuple[KT, VT] causing this error. Since you removed the similarity concept, the problem has gone, now the first match is chosen. So yes, the problem is fixed.
This is a follow-up for #3132 (this does not happen on master).
Consider this example found by @JukkaL in #3132:
It looks like this problem appears because
sqlite3.Row
has an untyped__iter__
and it is therefore considered a subtype ofIterable
protocol and therefore matches another overload ofdict
constructor (annotatingRow.__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 matchesAny
).The text was updated successfully, but these errors were encountered: