Skip to content

Deprecate size parameter on WorkerPool in favor of spawn#135

Merged
conradbzura merged 5 commits intowool-labs:mainfrom
conradbzura:134-deprecate-size-favor-spawn
Mar 28, 2026
Merged

Deprecate size parameter on WorkerPool in favor of spawn#135
conradbzura merged 5 commits intowool-labs:mainfrom
conradbzura:134-deprecate-size-favor-spawn

Conversation

@conradbzura
Copy link
Copy Markdown
Contributor

@conradbzura conradbzura commented Mar 28, 2026

Summary

Rename the size parameter on WorkerPool to spawn across all three __init__ overloads and internal implementation. The size/lease parameter pair read ambiguously — size could refer to total pool capacity rather than the number of spawned workers. The new spawn name makes the semantics explicit: spawn is how many workers the pool starts, lease is how many additional discovered workers it accepts.

WorkerPool(size=N) continues to work at runtime via a DeprecationWarning, and type checkers (pyright, mypy) flag it at static analysis time via PEP 702 @deprecated overloads. Passing both size and spawn raises TypeError. All internal references (_resolve_spawn, _worker_context, match arms) and README documentation use spawn as the canonical name.

Closes #134

Proposed changes

Rename size to spawn in the implementation signature

Replace size with spawn in all three @overload signatures (ephemeral, durable, hybrid) and the implementation body. Rename the _resolve_size helper to _resolve_spawn and update its error message from "Size must be non-negative" to "Spawn must be non-negative". The _worker_context method parameter and all match-arm bindings now use spawn.

Add runtime deprecation bridge for size

The implementation signature accepts both spawn and size as optional parameters. When size is provided alone, emit a DeprecationWarning at stacklevel=2 (pointing to the caller's frame) and forward the value to spawn. When both are provided, raise TypeError.

Update README documentation

Replace size with spawn in all code examples across the worker, discovery, and load-balancer READMEs. Update the mode table to use spawn as the column header and rewrite the spawn/lease explanation for clarity.

Test cases

# Test Suite Given When Then Coverage Target
1 TestWorkerPool The deprecated size parameter is passed WorkerPool is initialized Emit a DeprecationWarning Runtime deprecation warning
2 TestWorkerPool The spawn parameter is passed WorkerPool is initialized No DeprecationWarning is emitted Clean path for new API
3 TestWorkerPool Both size and spawn parameters are provided WorkerPool is initialized Raise TypeError Mutual exclusion guard
4 TestWorkerPool The deprecated size parameter with value 4 WorkerPool is initialized Create a valid pool identical to spawn=4 Value forwarding
5 TestWorkerPool The deprecated size parameter with value -1 WorkerPool is initialized Emit a DeprecationWarning and raise ValueError Negative value forwarding
6 TestWorkerPool The deprecated size parameter with value 0 and CPU count available WorkerPool is initialized Emit a DeprecationWarning and create a valid pool Zero/CPU-count resolution
7 TestWorkerPool The deprecated size parameter and a discovery service WorkerPool is initialized Emit a DeprecationWarning and create a valid pool Hybrid mode compatibility
8 TestWorkerPool The deprecated size parameter with value 4 and lease of 8 WorkerPool is initialized Emit a DeprecationWarning and create a valid pool Lease combination
9 TestWorkerPool The deprecated size parameter is passed WorkerPool is initialized Warning filename points to the test file Stacklevel correctness

The size/lease pair reads ambiguously — size could mean total pool
capacity rather than the number of spawned workers. Renaming to spawn
makes the semantics explicit.

WorkerPool(spawn=N) is the primary API. WorkerPool(size=N) continues
to work but emits a DeprecationWarning. Passing both raises TypeError.
All internal references (_resolve_spawn, match arms, _worker_context)
now use spawn as the canonical name.

BREAKING CHANGE: _resolve_size renamed to _resolve_spawn; error message
changed from "Size must be non-negative" to "Spawn must be non-negative"
All existing tests now use spawn= instead of size= to exercise the
primary API. Four new tests cover the deprecation path: warning
emission, no-warning for spawn, TypeError on both, and value
forwarding from size to spawn.
Five new tests cover the deprecated size parameter interacting with
other code paths: negative value forwarding, zero/CPU-count resolution,
hybrid mode with discovery, lease combination, and stacklevel
correctness. Two stale test names referencing "size" are also fixed.
Replace size with spawn in all examples, the mode table, and the
architecture diagram. Add lease as a column in the mode table and
split the spawn/lease explanation into separate paragraphs for
clarity.
@conradbzura conradbzura marked this pull request as ready for review March 28, 2026 01:23
@conradbzura conradbzura self-assigned this Mar 28, 2026
@conradbzura conradbzura merged commit 2fbbe97 into wool-labs:main Mar 28, 2026
4 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.

Deprecate size parameter on WorkerPool in favor of spawn

1 participant