Optimize shell and shell2 method type hints using @overload and Literal#194
Merged
codeskyblue merged 3 commits intomasterfrom Sep 8, 2025
Merged
Optimize shell and shell2 method type hints using @overload and Literal#194codeskyblue merged 3 commits intomasterfrom
codeskyblue merged 3 commits intomasterfrom
Conversation
Co-authored-by: codeskyblue <3281689+codeskyblue@users.noreply.github.com>
…mpatibility Co-authored-by: codeskyblue <3281689+codeskyblue@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] shell这个函数和shell2返回到类型是Union不能被IDE很好的识别,请使用overload+Literal优化一下
Optimize shell and shell2 method type hints using @overload and Literal
Sep 8, 2025
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #194 +/- ##
==========================================
+ Coverage 34.64% 34.80% +0.15%
==========================================
Files 17 17
Lines 2179 2201 +22
Branches 320 327 +7
==========================================
+ Hits 755 766 +11
- Misses 1386 1390 +4
- Partials 38 45 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This PR improves IDE type inference for the
shellandshell2methods by replacing Union return types with precise@overloaddefinitions based on parameter combinations.Problem
Previously, the
shellandshell2methods used Union return types that made it difficult for IDEs and type checkers to infer the correct return type:Solution
Added precise
@overloaddefinitions withLiteraltypes that allow IDEs to understand exactly what type is returned based on the parameters:Implementation Details
shell method overloads:
stream=True→ returnsAdbConnectionstream=False, encoding=None→ returnsbytesstream=False, encoding=str→ returnsstrstrshell2 method overloads:
encoding=None→ returnsShellReturnRawencoding=str→ returnsShellReturnShellReturnUsed keyword-only arguments (
*) to make overloads more distinct for mypy compatibilityAdded proper imports with fallback to
typing_extensionsfor Python 3.8 supportUpdated abstract interfaces to match the new overload signatures
Benefits
Union[ShellReturn, ShellReturnRaw]typesTesting
Fixes #193.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.