feat: Add Python checker for multiple return types #218
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.
This commit introduces a new Go-based checker for Python code that detects functions and methods exhibiting multiple distinct return types.
The checker,
multiple-return-types
, performs the following:return
statements within each function/method.None
(e.g., by falling off the end or having no return statements).During integration, the following adjustments were made:
identifier:foo
fromidentifier:bar
) and call results (differentiatingcall_result:func1
fromcall_result:func2
) was generalized to "identifier" and "call_result" respectively. This was done to prevent the new checker from flagging numerous valid cases in existing library tests where different variables or calls of the same broad type are returned.None
returns when mixed with explicit returns was simplified. The checker now primarily focuses on explicit return type variations and considers a function to returnNoneType
if it has no explicit returns or if all explicit returns areNone
.checkers/python/testdata/path-traversal-open.test.py
) was annotated with# <expect-error>
as the new checker correctly identified a function with multiple return types.A comprehensive test suite (
checkers/python/multiple_return_types.test.py
) has been added to validate the checker's functionality across various scenarios, including mixed types, implicit returns, nested structures, and class methods.The checker is registered and built as part of the existing
make generate-registry
andmake build
process.