fix: replace Optional[callable] with Optional[Callable] in type annotations#33920
Closed
blut-agent wants to merge 1 commit into
Closed
fix: replace Optional[callable] with Optional[Callable] in type annotations#33920blut-agent wants to merge 1 commit into
blut-agent wants to merge 1 commit into
Conversation
…ations The builtin 'callable' is not a valid generic type for static type checkers. Replace all instances of Optional[callable] with the correct typing.Callable annotation, and add the missing 'Callable' import where needed. Files fixed: - hermes_cli/dingtalk_auth.py: on_waiting callback - run_agent.py: stream_callback in chat() and run_conversation() - agent/conversation_loop.py: stream_callback in run_conversation() - gateway/stream_consumer.py: on_new_message callback - tools/delegate_tool.py: _build_child_progress_callback return type - plugins/disk-cleanup/disk_cleanup.py: confirm callback in deep()
Collaborator
Contributor
Author
|
Closing — this is a subset of #32985 (still open, covers Callable + Any fixes) and overlaps with #32869. The broader PR is the right place for this fix. Thanks @alt-glitch for flagging. |
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.
Problem
The builtin
callableis not a valid generic type for static type checkers like mypy/pyright. WhileOptional[callable]works at runtime (Python accepts it), it's technically incorrect and would flag errors in strict type-checking mode.This pattern appeared in 6 files across the codebase.
Fix
Replace all instances of
Optional[callable]with the correctOptional[Callable[...]]annotation, adding the missingCallableimport where needed.Files changed:
on_waiting: Optional[Callable[[], None]]stream_callback: Optional[Callable[[str], None]](2 places)stream_callback: Optional[Callable[[str], None]]on_new_message: Optional[Callable[[], None]](already hadCallableimported but used lowercase)Optional[Callable[..., None]]confirm: Optional[Callable[[Dict[str, Any]], bool]]Testing