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

Pylint doesn't warn if isinstance's second argument doesn't consist entirely of types. #3308

Closed
bnsh opened this issue Dec 17, 2019 · 2 comments · Fixed by #3404
Closed

Pylint doesn't warn if isinstance's second argument doesn't consist entirely of types. #3308

bnsh opened this issue Dec 17, 2019 · 2 comments · Fixed by #3404
Labels
Checkers Related to a checker Good first issue Friendly and approachable by new contributors

Comments

@bnsh
Copy link

bnsh commented Dec 17, 2019

Not really sure if it's a real issue... But, the bug (my own) bit me, and I thought pylint would have saved me from it...

Here's the example code:

#! /usr/bin/env python3
# vim: expandtab shiftwidth=4 tabstop=4

"""This program demonstrates that pylint doesn't catch
   instanceof "types" """

def main():
    print(isinstance("x", hash))

if __name__ == "__main__":
    main()

If I run it tho, I get:

$ python3 ./demo.py 
Traceback (most recent call last):
  File "./demo.py", line 11, in <module>
    main()
  File "./demo.py", line 8, in main
    print(isinstance("x", hash))
TypeError: isinstance() arg 2 must be a type or tuple of types

it's pylint clean tho:

$ python3 -m pylint --version
pylint 2.4.3
astroid 2.3.2
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0]
$ python3 -m pylint -r n demo.py 

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Is that a problem? (In this case, I said "hash" where I meant "dict")

Thanks!

@PCManticore PCManticore added Checkers Related to a checker Good first issue Friendly and approachable by new contributors labels Dec 30, 2019
@PCManticore
Copy link
Contributor

Thank you for the report. This is definitely an issue we should be able to detect.

@anubh-v
Copy link
Contributor

anubh-v commented Feb 12, 2020

I'll attempt this.

PCManticore added a commit that referenced this issue Feb 13, 2020
… type (#3404)

The second argument to isinstance must be either a type or a tuple of types.

Close #3308 

Co-authored-by: Claudiu Popa <pcmanticore@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants