Pylint: False positive isinstance-second-argument-not-valid-type when testing typing.Iterable

Created on 24 Apr 2020  路  6Comments  路  Source: PyCQA/pylint

Steps to reproduce

from typing import Iterable

print(isinstance([], Iterable))

Similar issues exist for other generic collection types such as Sized, Mapping etc.

Current behavior

Second argument of isinstance is not a type (isinstance-second-argument-not-valid-type)

Expected behavior

No warning is issued.

When collections.abc.Iterable is used instead, there is no warning issued. But the way that class is aliased in the typing module is probably too complex for static analysis to deal with and there doesn't seem to be explicit support yet to work around that.

pylint --version output

$ pylint --version
pylint 2.5.0-dev1
astroid 2.4.0
Python 3.8.2 (default, Mar 05 2020, 18:58:42) [GCC]

The astroid version is a dev snapshot as well, but not reported as such. To be exact, I'm using pylint at 0ccf1bca and astroid at f6a36d91.

bug topic-typing

Most helpful comment

Also with typing.List

All 6 comments

Thanks, I can confirm the bug. It seems we're inferring typing.Iterable as an instance rather than a class.

I confirm the bug with typing.Dict.

Also with typing.List

Also with typing.Generator.

Also happened with typing.Match, pylint version 2.5.2.

I think we can safely assume it is all protocols, so we don't need to exhaustively and separately report them all.

Was this page helpful?
0 / 5 - 0 ratings