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
I am trying to add some type hints to a module that takes a filename and reads it with a caller supplied reader (most common csv.reader and csv.DictReader). I noticed when I do not supply a default, mypy is fine, however, when I do, it complains about incompatibility.
Python: 3.9.1
importcsvfromtypingimportCallable, Iterable, Iterator, Text, TypeVarT=TypeVar('T')
deffoo(x: str, reader: Callable[[Iterable[Text]], Iterator[T]]) ->Iterator[T]:
returnreader(x)
# Is fine, resolves to Iterator[List[str]]x=foo('bar.txt', csv.reader)
# Complains that _reader is not compatible with Iterator[T]defbaz(x: str, reader: Callable[[Iterable[Text]], Iterator[T]] =csv.reader) ->Iterator[T]:
returnreader(x)
I am trying to add some type hints to a module that takes a filename and reads it with a caller supplied reader (most common csv.reader and csv.DictReader). I noticed when I do not supply a default, mypy is fine, however, when I do, it complains about incompatibility.
Python: 3.9.1
When I look at the _reader definition I see
So it is a subclass of
Iterator[List[str]]
which should be compatible withIterator[T]
The text was updated successfully, but these errors were encountered: