Skip to content

fix: add missing type hints and improve test logging#12810

Merged
enyst merged 3 commits intoOpenHands:mainfrom
hobostay:fix/type-hints-and-logging-improvements
Feb 18, 2026
Merged

fix: add missing type hints and improve test logging#12810
enyst merged 3 commits intoOpenHands:mainfrom
hobostay:fix/type-hints-and-logging-improvements

Conversation

@hobostay
Copy link
Copy Markdown
Contributor

Summary

This PR includes several code quality improvements to enhance type safety and logging practices:

  • Add missing return type annotations to openhands/io/json.py
  • Add missing return type annotation to openhands/memory/view.py
  • Replace print() statements with proper logging in tests/e2e/test_settings.py

Changes

1. Type hints in openhands/io/json.py

  • Add return type annotation -> str to dumps() function
  • Add parameter type annotation : str and return type -> Any to loads() function
  • Import Any from typing module

2. Type hint in openhands/memory/view.py

  • Add return type annotation -> Iterator[Event] to __iter__() method
  • Import Iterator from collections.abc

3. Logging improvements in tests/e2e/test_settings.py

  • Replace all print() statements with proper logging using logger.info(), logger.warning(), and logger.error()
  • Add logging module import and create logger instance
  • Follows best practices for test logging and enables better log management

Testing

The changes are minimal and focused:

  • Type annotations don't affect runtime behavior
  • Logging changes maintain the same information output but use proper logging infrastructure
  • All existing tests should continue to pass

Checklist

  • Code follows the project's style guidelines
  • Changes are backward compatible
  • No breaking changes introduced

🤖 Generated with Claude Code

This PR includes several code quality improvements:

1. Add type hints to openhands/io/json.py:
   - Add return type annotation `-> str` to `dumps()` function
   - Add parameter type annotation `: str` and return type `-> Any` to `loads()` function
   - Import `Any` from typing module

2. Add type hint to openhands/memory/view.py:
   - Add return type annotation `-> Iterator[Event]` to `__iter__()` method
   - Import `Iterator` from collections.abc

3. Improve logging in tests/e2e/test_settings.py:
   - Replace all `print()` statements with proper logging using `logger.info()`, `logger.warning()`, and `logger.error()`
   - Add logging module import and create logger instance
   - This follows best practices for test logging and enables better log management

These changes improve code quality, type safety, and maintainability without affecting functionality.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

Good improvements to type safety and logging! Found a few areas that could be enhanced further for consistency and best practices.

Comment thread openhands/io/json.py
Comment thread openhands/io/json.py
Comment thread tests/e2e/test_settings.py
The Iterator[Event] type annotation conflicts with BaseModel's __iter__
method which returns Generator[tuple[str, Any], None, None].
Removing the explicit type annotation allows the method to work correctly.
Copy link
Copy Markdown
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

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

Thank you!

@enyst enyst merged commit 6676cae into OpenHands:main Feb 18, 2026
18 checks passed
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.

3 participants