Fix ty unresolved-attribute warnings and add mypy back - #1737
Fix ty unresolved-attribute warnings and add mypy back#1737tleonhardt wants to merge 19 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 5960 +23
==========================================
+ Hits 5917 5939 +22
- 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.
|
@KelvinChung2000 Could you please review the changes in @kmvanbrunt Could you please review changes outside of
|
…ommandFunc Protocol classes Also: - Switched some types in cmd2.py from `Callable[..., Any]` to `BoundCommandFunc` - Removed a number of `cast` calls in cmd2.py which were no longer needed
…unc and UnboundCommand func Also: - Restored the simple attribute definition for `__name__` attribute in BoundCommandFunc and UnboundCommandFund
…ntation Deleted _CommandFunc from annotated.py and replaced with BoundCommandFunc from types.py
…ction to make some types less restrictive
It turns out that ty is better at some things and mypy is better at others when it comes to type checking. So ty is at least not yet a purely superior replacement for mypy.
Most modern agent harness CLIs like codex, agy, opencode, hemes, pi, oh-my-pi, and tau all read AGENTS.md by default. It has emerged as the single file used by most agentic AI tools. Leaving GEMINI.md in place for now since Gemini CLI doesn't read AGENTS.md by default.
|
@KelvinChung2000 @kmvanbrunt Ok, I think this is ready for another review. I ended up adding |
Add
mypyback in addition totyfor type checking.Also fixes
tyunresolved-attribute warnings and stop globally ignoring them withinty.toml.Major changes:
mypyback so now bothtyandmypyare used for type checking - each are better at some thingsBoundCommandFuncandUnboundCommandFuncTypeAliases 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)