Better message for truthy functions#15193
Merged
hauntsaninja merged 9 commits intopython:masterfrom May 13, 2023
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
hauntsaninja
approved these changes
May 13, 2023
Collaborator
hauntsaninja
left a comment
There was a problem hiding this comment.
Overall looks great! Just had a minor comment
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
Thanks for the review @hauntsaninja! |
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: arviz (https://github.com/arviz-devs/arviz)
- arviz/tests/base_tests/test_utils.py:250: error: Function "Callable[[Any, Any], Any]" could always be true in boolean context [truthy-function]
+ arviz/tests/base_tests/test_utils.py:250: error: Function "_stack" could always be true in boolean context [truthy-function]
spark (https://github.com/apache/spark)
- python/pyspark/ml/torch/distributor.py:658: error: Function "Callable[..., Any]" could always be true in boolean context [truthy-function]
+ python/pyspark/ml/torch/distributor.py:658: error: Function "framework_wrapper_fn" could always be true in boolean context [truthy-function]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/settings.py:1708: error: Function "Callable[[Settings, T], T]" could always be true in boolean context [truthy-function]
+ src/prefect/settings.py:1708: error: Function "value_callback" could always be true in boolean context [truthy-function]
- src/prefect/results.py:101: error: Function "Callable[[TaskRunContext, dict[str, Any]], str | None]" could always be true in boolean context [truthy-function]
+ src/prefect/results.py:101: error: Function "cache_key_fn" could always be true in boolean context [truthy-function]
- src/prefect/engine.py:1521: error: Function "Callable[[TaskRunContext, dict[str, Any]], str | None]" could always be true in boolean context [truthy-function]
+ src/prefect/engine.py:1521: error: Function "cache_key_fn" could always be true in boolean context [truthy-function]
ibis (https://github.com/ibis-project/ibis)
- ibis/common/caching.py:100: error: Function "Callable[[Any], Any]" could always be true in boolean context [truthy-function]
+ ibis/common/caching.py:100: error: Function "key" could always be true in boolean context [truthy-function]
pyppeteer (https://github.com/pyppeteer/pyppeteer)
- pyppeteer/browser.py:54: error: Function "Callable[[], Awaitable[None]]" could always be true in boolean context [truthy-function]
+ pyppeteer/browser.py:54: error: Function "closeCallback" could always be true in boolean context [truthy-function]
|
hauntsaninja
approved these changes
May 13, 2023
Collaborator
hauntsaninja
left a comment
There was a problem hiding this comment.
Looks great, thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes case 1 in #14529.
If this approach is correct, I will add the rest of the cases.
Updated message + tests.
Recommend we squash the commits when we merge since they are not clean but change is small enough to be one commit.
EDIT: This PR doesn't work quite as intended with walrus operator. It outputs two error msgs for both the function value and target. This seemed the least bad solution as: