-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix invalid type false positive #8206
Changes from 1 commit
e0d32da
4741057
07d595e
8e42987
dc8f72b
bad4805
95cfe9f
e4df864
e6b70c2
3d0ebe7
1c62667
673fa05
bb38e7c
66d21ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -806,6 +806,10 @@ def _is_invalid_isinstance_type(arg: nodes.NodeNG) -> bool: | |||||
return False | ||||||
if isinstance(inferred, astroid.Instance) and inferred.qname() == BUILTIN_TUPLE: | ||||||
return False | ||||||
if isinstance(arg, nodes.BinOp) and arg.op == "|": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reckon this check should only be done for python version that support PEP604 and the
Suggested change
where:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'll add that once the rest is figured out. And maybe a shorter name would be nice π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe You can also rename it in |
||||||
return _is_invalid_isinstance_type(arg.left) and _is_invalid_isinstance_type( | ||||||
arg.right | ||||||
) | ||||||
return True | ||||||
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# pylint: disable = missing-docstring | ||
nickdrozd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isinstance(0, int | str) | ||
isinstance(0, int | int | int) | ||
isinstance(0, int | str | list | float) | ||
isinstance(0, (int | str) | (list | float)) |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,2 @@ | ||||||||||||||||
[testoptions] | ||||||||||||||||
min_pyver=3.10 | ||||||||||||||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you could allow the test to run also for earlier versions like was done in
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think about it, this check is different because it doesn't deal with type annotations. In this case the types involved will actually be called, so I think this option won't apply. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't have to explicitly write
I think you are right. These are not annotations it the actual code. so if someone uses the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use the new
UnionType
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of what I assume are inference failures, I couldn't cover all the test cases without checking both the inferred value and the superficial value. Is there a better way to do this?