-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Consistency between is
/is not
and ==
/!=
when comparing types for unidiomatic-typecheck
#10170
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
Changes from 3 commits
f30417c
0a09606
4380fbe
59a0a5d
d61b85c
986d1b4
ac6e517
3974ec1
dc13f1b
59f975c
74c2fa7
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Comparisons of types won't raise an ``unidiomatic-typecheck`` warning anymore, consistent with the behavior applied only for ``==`` previously. | ||
|
||
Closes #10161 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,15 +343,12 @@ def _check_type_x_is_y( | |
): | ||
return | ||
|
||
if operator in {"is", "is not"} and _is_one_arg_pos_call(right): | ||
jacobtylerwalls marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if operator in {"!=", "==", "is", "is not"} and _is_one_arg_pos_call(right): | ||
Pierre-Sassoulas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
right_func = utils.safe_infer(right.func) | ||
if ( | ||
isinstance(right_func, nodes.ClassDef) | ||
and right_func.qname() == TYPE_QNAME | ||
): | ||
# type(x) == type(a) | ||
right_arg = utils.safe_infer(right.args[0]) | ||
if not isinstance(right_arg, LITERAL_NODE_TYPES): | ||
# not e.g. type(x) == type([]) | ||
return | ||
return | ||
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'm not sure I would change this. 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. agree with jacob, shall we keep this guard block that checks for literal node types? 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. At this point we already know that the left arg is type(something), once we know the right argument is starting by 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 think it depends on whether we want to retain current behavior of raising a message for Couldn't dig into the related PR as it was merged >10 years ago in a different repository, but the separation of 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 re-read the issue. Here's my context:
Let's just fix the is/is not thing and keep these test cases and the open follow-up issues for:
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. |
||
self.add_message("unidiomatic-typecheck", node=node) |
Uh oh!
There was an error while loading. Please reload this page.