Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -381,7 +381,8 @@ def test_pin_if_ready_none_when_absent():
def test_pin_if_ready_returns_unpinned_entry_when_not_ready():
"""The producer needs "present but not ready" told apart from "absent":
the first is NACKed as retryable, the second as a miss."""
the first is NACKed as retryable, the second as a miss.
"""
cache = EmbeddingCache(num_blocks=4)
cache.alloc("h", 1) # not-ready
entry = cache.pin_if_ready("h")
@@ -131,7 +131,8 @@ def test_has_cache_item_false_when_not_consumer(monkeypatch):
def test_connector_keys_on_identifier_not_mm_hash(monkeypatch):
"""The connector must key the encoder cache on feature.identifier (what
has_cache_item is called with), NOT feature.mm_hash."""
has_cache_item is called with), NOT feature.mm_hash.
"""
s = _make_scheduler(monkeypatch)
req = _Request([_Feature("PROC_KEY", length=1, identifier="ENC_KEY")])
s.update_state_after_alloc(req, 0)
@@ -201,7 +202,8 @@ def test_loads_only_serves_hashes_touched_this_step(monkeypatch):
def test_repeated_reload_same_step_loads_once(monkeypatch):
"""The same mm_hash requested twice in one step must appear in
meta.loads exactly once."""
meta.loads exactly once.
"""
s = _make_scheduler(monkeypatch)
_seed_cached(s, "a", n_blocks=2)
@@ -224,7 +226,8 @@ def test_load_not_emitted_for_uncached_entry(monkeypatch):
def test_load_pin_protects_blocks_until_completion(monkeypatch):
"""Loaded blocks stay pinned until the worker reports the load memcpy
complete. Observable: a save that needs eviction cannot reclaim a
still-pinned loaded entry, but can once the completion report arrives."""
still-pinned loaded entry, but can once the completion report arrives.
"""
# 2 blocks, both occupied by "a" (ready).
s = _make_scheduler(monkeypatch, num_blocks=2)
_seed_cached(s, "a", n_blocks=2)
@@ -251,7 +254,8 @@ def test_load_pin_protects_blocks_until_completion(monkeypatch):
def _can_evict(s: ECCPUScheduler, mm_hash: str, n_blocks: int) -> bool:
"""Whether a new save of `mm_hash` can claim `n_blocks`, i.e. whether the
blocks currently held by other entries are reclaimable."""
blocks currently held by other entries are reclaimable.
"""
s.update_state_after_alloc(_Request([_Feature(mm_hash, length=n_blocks)]), 0)
meta = s.build_connector_meta(scheduler_output=None)
return mm_hash in meta.saves
@@ -311,7 +315,8 @@ def test_late_report_does_not_release_a_later_load_of_same_hash(monkeypatch):
def test_region_full_skips_save_and_never_blocks(monkeypatch):
"""When the region is fully occupied by pinned entries, new saves are
silently skipped and ensure_cache_available never blocks."""
silently skipped and ensure_cache_available never blocks.
"""
s = _make_scheduler(monkeypatch, num_blocks=1)
_seed_cached(s, "pinned", n_blocks=1)
s._cache.pin("pinned")
@@ -330,7 +335,8 @@ def test_region_full_skips_save_and_never_blocks(monkeypatch):
def test_producer_only_never_emits_loads(monkeypatch):
"""A producer-only scheduler must never populate meta.loads, even when
entries are ready."""
entries are ready.
"""
s = _make_scheduler(monkeypatch, ec_role="ec_producer")
req = _Request([_Feature("h1", length=1)])
@@ -372,7 +378,8 @@ def test_consumer_only_has_cache_item(monkeypatch):
def test_save_not_emitted_for_already_cached_entry(monkeypatch):
"""An entry already in the cache (from a prior save) must not trigger
a second allocation or appear in meta.saves again."""
a second allocation or appear in meta.saves again.
"""
s = _make_scheduler(monkeypatch)
req = _Request([_Feature("h1", length=1)])
@@ -393,7 +400,8 @@ def test_save_not_emitted_for_already_cached_entry(monkeypatch):
def test_update_connector_output_ignores_foreign_meta(monkeypatch):
"""A worker output whose payload is not an ECCPUWorkerMetadata is a
no-op — no cache mutation, no crash."""
no-op — no cache mutation, no crash.
"""
s = _make_scheduler(monkeypatch)
_seed_cached(s, "a", n_blocks=1)
@@ -407,7 +415,8 @@ def test_update_connector_output_ignores_foreign_meta(monkeypatch):
def test_update_connector_output_ignores_unknown_report(monkeypatch):
"""Reports for a never-seen save hash or a transfer id this scheduler never
dispatched are dropped rather than mutating unrelated state."""
dispatched are dropped rather than mutating unrelated state.
"""
s = _make_scheduler(monkeypatch)
s.update_connector_output(_WorkerOutput(saves=["gone"], loads=[4242]))
assert s.has_cache_item("gone") is False
@@ -419,7 +428,8 @@ def test_update_connector_output_ignores_unknown_report(monkeypatch):
def test_has_pending_push_work_tracks_inflight_save(monkeypatch):
"""A dispatched-but-unconfirmed save keeps push work pending until the
completion report marks it ready."""
completion report marks it ready.
"""
s = _make_scheduler(monkeypatch)
assert s.has_pending_push_work() is False
@@ -434,7 +444,8 @@ def test_has_pending_push_work_tracks_inflight_save(monkeypatch):
def test_has_pending_push_work_tracks_inflight_load(monkeypatch):
"""A dispatched-but-unconfirmed load keeps push work pending until the
unpin completion report arrives."""
unpin completion report arrives.
"""
s = _make_scheduler(monkeypatch)
_seed_cached(s, "a", n_blocks=1)
assert s.has_pending_push_work() is False # ready + unpinned
@@ -453,7 +464,8 @@ def test_has_pending_push_work_tracks_inflight_load(monkeypatch):
def test_shutdown_disables_roles_and_cleans_region(monkeypatch):
"""After shutdown the scheduler serves no items and the region is
cleaned up."""
cleaned up.
"""
s = _make_scheduler(monkeypatch, num_blocks=2)
_seed_cached(s, "a", n_blocks=2)
assert s.has_cache_item("a") is True
@@ -98,7 +98,8 @@ def test_second_instance_opens_existing_file_and_shares_memory():
def test_only_creator_unlinks_file_on_cleanup():
"""Critical contract: if the non-creator unlinks, the creator's mmap path
becomes a dangling backing file and a third opener would create a new one
out from under the creator."""
out from under the creator.
"""
instance_id = str(uuid.uuid4())
r1 = ECSharedRegion(
engine_id=instance_id,
@@ -215,7 +216,8 @@ def test_madvise_einval_selects_fallback_for_whole_region(monkeypatch):
def test_non_creator_does_not_probe_or_populate(monkeypatch):
"""Only the creator pre-faults. A second opener must not probe the advice
nor re-touch pages the creator already populated."""
nor re-touch pages the creator already populated.
"""
from vllm.distributed.ec_transfer.ec_connector.cpu import ec_shared_region as esr
instance_id = str(uuid.uuid4())
@@ -312,7 +314,8 @@ def test_madvise_unexpected_oserror_propagates(monkeypatch):
def test_pin_memory_success_sets_flag(region):
"""When cudaHostRegister returns 0, _is_pinned flips to True
and cleanup will correspondingly call cudaHostUnregister."""
and cleanup will correspondingly call cudaHostUnregister.
"""
fake_cudart = MagicMock()
success = MagicMock()
success.value = 0
@@ -332,7 +335,8 @@ def test_pin_memory_success_sets_flag(region):
def test_pin_memory_failure_leaves_flag_false():
"""If cudaHostRegister fails (non-zero), don't pretend it succeeded —
cleanup must NOT call cudaHostUnregister on memory we never registered."""
cleanup must NOT call cudaHostUnregister on memory we never registered.
"""
r = _make_region()
try:
fake_cudart = MagicMock()
@@ -363,7 +363,8 @@ def test_save_caches_coalesces_only_adjacent_blocks(
def test_save_caches_noop_when_mm_hash_not_in_saves(make_worker):
"""When the scheduler hasn't pre-allocated blocks for ``mm_hash``,
``save_caches`` + ``flush_saves`` is a pure no-op."""
``save_caches`` + ``flush_saves`` is a pure no-op.
"""
worker = make_worker()
sentinel = 0x42
worker._region.blocks.fill_(sentinel)
@@ -381,7 +382,8 @@ def test_save_caches_noop_when_mm_hash_not_in_saves(make_worker):
)
def test_save_caches_noop_for_non_save_rank(make_worker, tp_rank, pcp_rank):
"""Only TP rank 0 + PCP rank 0 writes to mmap. All other combinations
must skip the save entirely."""
must skip the save entirely.
"""
worker = make_worker(tp_rank=tp_rank, pcp_rank=pcp_rank)
sentinel = 0x42
worker._region.blocks.fill_(sentinel)
@@ -396,7 +398,8 @@ def test_save_caches_noop_for_non_save_rank(make_worker, tp_rank, pcp_rank):
def test_save_caches_raises_when_allocated_blocks_too_small(make_worker):
"""``save_caches`` must raise ``AssertionError`` when the encoder output
is larger than the allocated block space."""
is larger than the allocated block space.
"""
worker = make_worker()
src = torch.zeros(3 * _HIDDEN_DIM, dtype=_DTYPE)
with pytest.raises(AssertionError, match="exceeds allocated blocks"):
@@ -549,7 +552,8 @@ def test_start_load_caches_noop_when_loads_is_empty(make_worker):
def test_start_load_caches_skips_cached_and_loads_new_in_same_step(make_worker):
"""Every hash in ``meta.loads`` is copied from mmap, including one whose
key is already resident in ``encoder_cache`` — there is no worker-side
skip."""
skip.
"""
worker = make_worker()
n_blocks = 3
src_orig = torch.arange(n_blocks * _HIDDEN_DIM, dtype=_DTYPE).reshape(
@@ -778,7 +782,8 @@ def test_buffer_pool_is_reused_across_save_steps(make_worker):
@_requires_accelerator
def test_buffer_pool_is_reused_across_load_steps(make_worker):
"""Once a load copy completes its descriptor buffers return to the pool and
are reused by the next call — no reallocation."""
are reused by the next call — no reallocation.
"""
worker = make_worker()
worker._region.blocks[0].fill_(0x01)
worker._region.blocks[1].fill_(0x02)
@@ -849,7 +854,8 @@ def test_init_pins_memory_when_available(pin_available, expected_pinned):
def test_shutdown_calls_region_cleanup_and_swallows_errors(caplog_vllm):
"""``shutdown`` must always call ``region.cleanup`` — and must never
raise."""
raise.
"""
worker = object.__new__(ECCPUWorker)
mock_region = Mock(spec=ECSharedRegion)
worker._region = mock_region