-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 a false positive for 'missing-parentheses-for-call-in-test' and add doc example #8185
Fix a false positive for 'missing-parentheses-for-call-in-test' and add doc example #8185
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8185 +/- ##
==========================================
- Coverage 95.53% 95.53% -0.01%
==========================================
Files 177 177
Lines 18622 18616 -6
==========================================
- Hits 17791 17785 -6
Misses 831 831
|
f8747c4
to
3fac051
Compare
2a24c23
to
1495c40
Compare
5507480
to
d8652d8
Compare
This comment has been minimized.
This comment has been minimized.
d8652d8
to
cb2ea07
Compare
This comment has been minimized.
This comment has been minimized.
cb2ea07
to
0a3c854
Compare
0a3c854
to
e9804bd
Compare
This started as a fun chat GPT fueled adventure and then I did not manage to make it raise like it should and went on another more painful adventure. |
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.
Two nits! Love this adventure 😄
# Just forcing the generator to infer all elements. | ||
# astroid.exceptions.InferenceError are false positives | ||
# see https://github.com/PyCQA/pylint/pull/8185 | ||
list(call_inferred) |
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.
This is a nit, but can't we do the unpacking above where we are already catching InferenceError
?
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.
Sure, that not a nit that's an optimization 😄
374e628
to
056b3ee
Compare
8958d53
to
7c4381f
Compare
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
…th GhatGPT Prompt: Could you give me an example of bad code raising a 'missing-parentheses-for-call-in-test' message in pylint Could you make it more lively, the name is very generic ? That's kinda expected and boring, could you be more imaginative ? Also I don't think it should return a string, it's supposed to return a boolean. You need to add a ``# [missing-parentheses-for-call-in-test]`` on the line the actual message would be raised, could you update the bad example, please ? Final result: def is_it_a_good_day(): import random return random.choice([True, False]) if is_it_a_good_day: # [missing-parentheses-for-call-in-test] print("Today is a good day!") In this code, the line if is_it_a_good_day: would raise the "missing-parentheses-for-call-in-test" message, because Pylint is expecting to see a function call in the test expression of an if statement, but there are no parentheses after is_it_a_good_day. To correct this, you can add parentheses to make it a function call, as shown in the corrected code in my previous answer.
7c4381f
to
69e76de
Compare
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 69e76de |
Type of Changes
Description
Part of #5953 Actual conversation with ChatGPT that led to this MR:
Pierre Sassoulas: Could you give me an example of bad code raising a 'missing-parentheses-for-call-in-test' message in pylint
Sure, here's an example of code that would raise the "missing-parentheses-for-call-in-test" message in Pylint:
In this code, the line if example_func: raises the "missing-parentheses-for-call-in-test" message, because Pylint is expecting to see a function call in the test expression of an if statement, but there are no parentheses after example_func. To correct this, you can add parentheses to make it a function call:
Pierre Sassoulas
Could you make it more lively, the name is very generic ?
Sure, here's a more lively example that also includes a more descriptive function name:
In this code, the line if say_hello: raises the "missing-parentheses-for-test-call-in-if" message, because Pylint is expecting to see a function call in the test expression of an if statement, but there are no parentheses after say_hello. To correct this, you can add parentheses to make it a function call:
Pierre Sassoulas
That's kinda expected and boring, could you be more imaginative ? Also I don't think it should return a string, it's supposed to return a boolean.
Sure, here's a more imaginative example with a function that returns a boolean:
In this code, the line if is_it_a_good_day: raises the "missing-parentheses-for-call-in-test" message, because Pylint is expecting to see a function call in the test expression of an if statement, but there are no parentheses after is_it_a_good_day. To correct this, you can add parentheses to make it a function call:
Pierre Sassoulas
You need to add a
# [missing-parentheses-for-call-in-test]
on the line the actual message would be raised, could you update the bad example, please ?Of course! Here's the updated bad example with a comment indicating the location of the "missing-parentheses-for-call-in-test" message:
In this code, the line if is_it_a_good_day: would raise the "missing-parentheses-for-call-in-test" message, because Pylint is expecting to see a function call in the test expression of an if statement, but there are no parentheses after is_it_a_good_day. To correct this, you can add parentheses to make it a function call, as shown in the corrected code in my previous answer.