Skip to content

fix: fix annotated typing#1692

Open
KelvinChung2000 wants to merge 2 commits into
mainfrom
feat/annotated-paramspec-typing
Open

fix: fix annotated typing#1692
KelvinChung2000 wants to merge 2 commits into
mainfrom
feat/annotated-paramspec-typing

Conversation

@KelvinChung2000

Copy link
Copy Markdown
Contributor

close #1684

@KelvinChung2000 KelvinChung2000 changed the title chore: fix annotated typing fix: fix annotated typing Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.59%. Comparing base (6c6d844) to head (58655e0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1692      +/-   ##
==========================================
+ Coverage   99.57%   99.59%   +0.01%     
==========================================
  Files          23       23              
  Lines        5678     5681       +3     
==========================================
+ Hits         5654     5658       +4     
+ Misses         24       23       -1     
Flag Coverage Δ
unittests 99.59% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread cmd2/annotated.py
class _WithAnnotatedDecorator(Protocol):
"""The signature-preserving decorator ``with_annotated(...)`` returns (generic per call)."""

def __call__(self, fn: "Callable[_CommandParams, _CommandReturn]", /) -> "Callable[_CommandParams, _CommandReturn]": ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary string annotations for Callable can cause type variable binding issues.

Since Callable, _CommandParams, and _CommandReturn are already defined, there is no need to use string forward references here. Unquoted types ensure better compatibility and correct type variable binding across different type checkers (like mypy or pyright).

Recommend:

def __call__(self, fn: Callable[_CommandParams, _CommandReturn], /) -> Callable[_CommandParams, _CommandReturn]:

Comment thread cmd2/annotated.py
return handler, subcmd_name, parser_builder


_CommandParams = ParamSpec("_CommandParams")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend adding a brief bug fix blurb to the CHANGELOG.md file about fixing type hinting for this stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mypy complains about method decorated with with_annotated decorator

2 participants