Skip to content

fix: Pre-existing mypy type errors (#245)#282

Open
anchapin wants to merge 4 commits intomainfrom
fix/mypy-type-errors-245
Open

fix: Pre-existing mypy type errors (#245)#282
anchapin wants to merge 4 commits intomainfrom
fix/mypy-type-errors-245

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented Mar 8, 2026

Summary

This PR addresses GitHub issue #245 by fixing pre-existing mypy type errors that were blocking CI. The mypy configuration in pyproject.toml already disables the pre-existing error codes (as noted in the issue), but this PR makes actual code fixes to improve type safety:

Changes Made

1.

  • Added comments for docker module imports (docker package doesn't have type stubs)
  • Added for in the fallback case
  • Added and for docker client method calls

2.

  • Changed from try/except ImportError to TYPE_CHECKING pattern to avoid name redefinition issues
  • Added explicit type annotations to kwargs in and functions
  • Added comments to handle the case where sentry functions might be imported

3.

  • Added import
  • Added explicit type annotations to mock functions when error_tracking is not available

Verification

mypy src/ --config-file=pyproject.toml

Result: Success: no issues found in 145 source files

Notes

  • The pyproject.toml already contains settings for pre-existing error categories (assignment, attr-defined, arg-type, valid-type, union-attr, etc.)
  • These code fixes go beyond the configuration-based suppression to actually improve type safety
  • New errors will still be caught by mypy as they arise

Closes #245

The simulation engine tests were failing due to leftover data from
previous test runs. Added database cleanup in the autouse fixture to
ensure test isolation by deleting all SimulationBid records before
each test runs.

This fixes issue #242: Fix pre-existing test failures in codebase

Co-authored-by: openhands <openhands@all-hands.dev>
- Replace datetime.utcnow() with datetime.now(timezone.utc) in test fixtures
- Add timezone import to test_oauth_manager.py
- Fixes TypeError when comparing timezone-naive and timezone-aware datetimes

Co-authored-by: openhands <openhands@all-hands.dev>
- Import user_models.UserBase in test_performance_improvements.py
- Create all tables from both Base and UserBase in test_db fixture
- This fixes tests that failed with 'no such table: quota_usage'

Fixes #264
- Fix docker_sandbox.py: Add type ignore comments for docker module imports
- Fix error_tracking.py: Use TYPE_CHECKING pattern to avoid name redefinition
- Fix logger.py: Add Any type annotations to mock functions

Co-authored-by: openhands <openhands@all-hands.dev>
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @anchapin, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

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.

Fix 671 pre-existing mypy type errors

2 participants