Skip to content

refactor(core): split base.py into pool_state, pool_manager, health#38

Open
Pavkazzz wants to merge 3 commits intorefactor/2-contractsfrom
refactor/3-core
Open

refactor(core): split base.py into pool_state, pool_manager, health#38
Pavkazzz wants to merge 3 commits intorefactor/2-contractsfrom
refactor/3-core

Conversation

@Pavkazzz
Copy link
Copy Markdown
Collaborator

Summary

Stack 3/4 — splitting the monolithic base.py (709 lines).

  • PoolState: manages master/replica pool sets, waiting, factory delegation
  • BasePoolManager: thin orchestrator with public proxy methods for the full API
  • PoolHealthMonitor: background role checks — no longer accesses manager's private attributes
  • base.py: reduced to a 23-line re-export shim for backward compatibility
  • utils.py: genericize Stopwatch[KeyT], fix Dsn.with_() scheme preservation, defensive copy for Dsn.params

All methods removed from BasePoolManager are re-exposed as public proxies (release(), terminate(), master_pool_count, closing, etc.).

Review guide

hasql/pool_state.pyhasql/health.pyhasql/pool_manager.pyhasql/base.py

Test plan

  • ruff check passes
  • pytest tests/test_base_pool_manager.py tests/test_backward_compat.py tests/test_balancer_policy.py — 81 tests pass
  • pytest tests/test_abc.py — 5 tests pass (previously deselected in PR2)
  • pytest tests/test_utils.py — 56 regression tests pass
  • test_timeout_handling.py, test_trouble.py — require live PostgreSQL

🤖 Generated with Claude Code

Pavkazzz and others added 3 commits April 16, 2026 10:24
…onitor

- PoolState (hasql/pool_state.py): manages master/replica sets, waiting,
  pool factory delegation — replaces the stub from PR2
- BasePoolManager (hasql/pool_manager.py): thin orchestrator; all pool-state
  queries exposed as public proxy properties/methods
- PoolHealthMonitor (hasql/health.py): background health checks — takes
  pool_state + scalars instead of full manager reference (no transitive
  private access)
- hasql/base.py: reduced to 23-line re-export shim for backward compat
- hasql/utils.py: genericize Stopwatch[KeyT], fix Dsn.with_() scheme
  preservation, defensive copy for Dsn.params

Stack 3/4

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace Metrics(drivers=..., hasql=...) with
Metrics(pools=..., hasql=..., gauges=...) now that base.py
uses the new pool_manager.py. Backward-compat drivers property
converts PoolMetrics back to DriverMetrics.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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