Skip to content

refactor(contracts): PoolDriver ABC, acquire contexts, balancer refactoring#37

Open
Pavkazzz wants to merge 1 commit into
refactor/1-foundationsfrom
refactor/2-contracts
Open

refactor(contracts): PoolDriver ABC, acquire contexts, balancer refactoring#37
Pavkazzz wants to merge 1 commit into
refactor/1-foundationsfrom
refactor/2-contracts

Conversation

@Pavkazzz
Copy link
Copy Markdown
Collaborator

Summary

Stack 2/4 — interfaces and protocols.

  • PoolDriver ABC: formal interface for all DB drivers
  • AcquireContext, TimeoutAcquireContext, PoolAcquireContext: connection acquire contexts with deadline-based timeouts
  • PoolStateProvider Protocol: balancers now depend on Protocol instead of concrete manager — eliminates circular import
  • RandomWeightedBalancerPolicy: simplified weight formula

Note: hasql/pool_state.py in this PR contains only the Protocol stub. Full PoolState implementation comes in PR3.

Review guide

hasql/abc.pyhasql/acquire.pyhasql/balancer_policy/base.pygreedy.py, random_weighted.py, round_robin.py

Test plan

  • ruff check passes
  • pytest tests/test_acquire.py tests/test_policy.py — 17 tests pass
  • 3 test_abc.py tests deselected (depend on updated mock from PR3)

🤖 Generated with Claude Code

@Pavkazzz Pavkazzz force-pushed the refactor/2-contracts branch 2 times, most recently from 0778780 to 726bd15 Compare April 16, 2026 07:01
…efactoring

- Add PoolDriver ABC (hasql/abc.py): formal interface for all DB drivers
- Add acquire context classes (hasql/acquire.py): AcquireContext protocol,
  TimeoutAcquireContext, PoolAcquireContext with deadline-based timeout budget
- Add minimal PoolStateProvider protocol (hasql/pool_state.py stub)
- Refactor balancer policies to depend on PoolStateProvider protocol instead
  of concrete BasePoolManager — eliminates circular import
- Simplify RandomWeightedBalancerPolicy weight formula (MACHINE_EPSILON removed)

Stack 2/4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Pavkazzz Pavkazzz force-pushed the refactor/2-contracts branch from 726bd15 to d4a4c9c Compare April 16, 2026 07:25
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.

1 participant