Skip to content

Conversation

@goloroden
Copy link
Member

Summary

This PR improves code quality and maintainability by applying Python best practices and idioms throughout the codebase.

Changes

Type Hints & Type Safety

  • Added type aliases for commonly used types (EventStream, JsonDict, PreconditionList, etc.)
  • Removed unnecessary type annotations (redundant variable declarations)
  • Removed type: ignore comments by fixing the actual issues

Code Quality

  • Simplified error handling with idiomatic Python patterns (raise instead of raise exception_var)
  • Added _validate_response() helper method to reduce code duplication
  • Removed obsolete pylint disable comments
  • Fixed built-in shadowing (hashevent_hash in event.py:71)

Performance & Optimization

  • Optimized string processing (.ljust() instead of f-string formatting)
  • Removed unnecessary nested function in http_client.get()
  • Fixed Response.__str__() side effects (no longer consumes response body)

Clean Up

  • Removed unused EventSourcingDBJSONEncoder class
  • Replaced raise NotImplementedError with ... in abstract methods

Breaking Changes (Minor)

  • Changed BoundType and Order enums from str, Enum to normal Enum
    • Impact: Direct string comparison (BoundType.INCLUSIVE == "inclusive") will break
    • Migration: Use .value property (BoundType.INCLUSIVE.value == "inclusive")
    • Note: Normal usage as documented in README continues to work unchanged

Python Version Support

  • Updated to support Python 3.14 (requires-python = ">=3.11, <3.15")
  • All main dependencies (aiohttp, cryptography) support Python 3.14
  • QA pipeline already tests on Python 3.14

Test Updates

  • Updated test assertions to match new error message format (now returns actual server error messages instead of response repr)

Quality Assurance

  • ✅ Ruff: All checks passed
  • ✅ Pyright: 0 errors, 0 warnings
  • ✅ Tests: 65/65 passing

Notes

All changes improve code quality and maintainability without breaking the public API. The codebase now follows Python best practices and is more maintainable.

🤖 Generated with Claude Code

- Add type aliases for commonly used types (EventStream, JsonDict, etc.)
- Remove unnecessary type annotations and type: ignore comments
- Simplify error handling with idiomatic Python patterns
- Add _validate_response helper to reduce code duplication
- Fix built-in shadowing (hash -> event_hash)
- Optimize string processing (use .ljust() instead of f-string formatting)
- Remove unnecessary nested function in http_client.get()
- Fix Response.__str__ side effects (no longer consumes body)
- Remove obsolete pylint comments
- Replace raise NotImplementedError with ... in ABC
- Change Enum inheritance from str, Enum to normal Enum
- Remove unused EventSourcingDBJSONEncoder
- Update Python version support to include 3.14 (now: >=3.11, <3.15)
- Update test assertions to match new error message format

All changes improve code quality and maintainability without breaking
the public API. The only potential breaking change is the Enum modification
(BoundType, Order), which now returns Enum objects instead of strings when
stringified, though .value still returns the string value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@goloroden goloroden requested a review from a team as a code owner November 6, 2025 19:48
@goloroden goloroden changed the title refactor: improve Python idioms and code quality chore: improve Python idioms and code quality Nov 6, 2025
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@goloroden goloroden merged commit 8bc0a8a into main Nov 6, 2025
4 checks passed
@goloroden goloroden deleted the refactor/improve-python-idioms branch November 6, 2025 19:55
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.

2 participants