Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typing.Pattern not treated as a type #3537

Closed
jolaf opened this issue Apr 28, 2020 · 5 comments
Closed

typing.Pattern not treated as a type #3537

jolaf opened this issue Apr 28, 2020 · 5 comments

Comments

@jolaf
Copy link

jolaf commented Apr 28, 2020

The following code:

from re import compile as reCompile
from typing import Pattern

pattern = reCompile(r'')
print(isinstance(pattern, Pattern))

produces the following output:

$ python3 Test.py
True
$ pylint3 Test.py
************* Module Test
Test.py:5: [W1116(isinstance-second-argument-not-valid-type), ] Second argument of isinstance is not a type

$ python3 --version
Python 3.6.9
$ pylint3 --version
pylint 2.5.0
astroid 2.4.0
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 

Clearly, there's some problem with checking Pattern, as, for example, isinstance({}, Mapping) produces no warning.

@Pierre-Sassoulas
Copy link
Member

Thank you for the issue, I can reproduce this with the latest pylint.

@analog-cbarber
Copy link

Same with Sequence. Of course, technically these are not in fact type instances, but can still be used with isinstance.

@dumblob
Copy link

dumblob commented Jul 23, 2020

Totally agreed. IMHO most (any?) types/protocols from typing and collections (especially collections.abc) shall be treated as OK for isinstance().

Btw. this seems to be duplicate of #3507 and probably #2287 as well as #1162 (see discussions in them as there is also the idea to "copy" the implementation mypy uses - i.e. assert isinstance()).

@QBCARL
Copy link

QBCARL commented Aug 12, 2020

Same with Callable

@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

This issue seems to be fixed when testing with the latest pylint version.
If you still encounter issues, please report back and I'll reopen it.

@cdce8p cdce8p closed this as completed Oct 17, 2021
@cdce8p cdce8p added the typing label Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants