Fix ty unresolved-attribute warnings and stop globally ignoring them - #1737
Open
tleonhardt wants to merge 4 commits into
Open
Fix ty unresolved-attribute warnings and stop globally ignoring them#1737tleonhardt wants to merge 4 commits into
tleonhardt wants to merge 4 commits into
Conversation
Major changes: - Convert BoundCommandFunc and UnboundCommandFunc TypeAliases in types.py to Protocol classes for stricter type checking - Added `_NamedCallable` Protocol class in annotated.py for stricter type checking of function references - Used `getattr` and/or `cast()` to help resolve some type errors in cmd2.py Minor changes: - Added type ignore for `ty:unresolved-attribute` to a number of places we were already ignoring `attr-defined` for mypy (problem of different name for same type of check)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1737 +/- ##
==========================================
- Coverage 99.66% 99.64% -0.02%
==========================================
Files 23 23
Lines 5937 5949 +12
==========================================
+ Hits 5917 5928 +11
- Misses 20 21 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Changes include: 1. Removed _NamedCallable: Deleted the redundant protocol class definition of _NamedCallable from cmd2/annotated.py. 2. Imported type protocols: Imported BoundCommandFunc and UnboundCommandFunc from cmd2/types.py, and TypeAlias from typing. 3. Defined unified _CommandFunc alias: Formed a private, unified type alias _CommandFunc = BoundCommandFunc | UnboundCommandFunc[CmdOrSetT, [argparse.Namespace]]. 4. Updated function signatures: Replaced all annotations that previously used _NamedCallable in cmd2/annotated.py with _CommandFunc.
Member
Author
|
@KelvinChung2000 Could you please review the changes in @kmvanbrunt Could you please review changes outside of
|
KelvinChung2000
approved these changes
Aug 26, 2026
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.
Fix
tyunresolved-attribute warnings and stop globally ignoring them withinty.toml.Major changes:
BoundCommandFuncandUnboundCommandFuncTypeAliases intypes.pyto Protocol classes for stricter type checking_CommandFunctype alias in annotated.py based onBoundCommandFuncandUnboundCommandFuncgetattrand/orcast()to help resolve some type errors in cmd2.pyMinor changes:
ty:unresolved-attributeto a number of places we were already ignoringattr-definedfor mypy (problem of different name for same type of check)