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
If a is contained by B[T], then a must be of type T. I think mypy should make this inference, but it does not do so today.
from typing import Container
def check(o: object, c: Container[str]) -> str | None:
if o in c:
return o # Incompatible return value type (got "object", expected "Optional[str]")
return None
In the above case, I think it's clear that if o in c is True, then o must have the generic of c, in this case str.
Pitch
Any opportunity to correctly infer a type improves mypy and typechecking in general. This is just such an opportunity.
The text was updated successfully, but these errors were encountered:
Feature
If
a
is contained byB[T]
, thena
must be of typeT
. I think mypy should make this inference, but it does not do so today.In the above case, I think it's clear that if
o in c
isTrue
, theno
must have the generic ofc
, in this casestr
.Pitch
Any opportunity to correctly infer a type improves mypy and typechecking in general. This is just such an opportunity.
The text was updated successfully, but these errors were encountered: