[Bugfix][CLI] Include inherited field docstrings in get_attr_docs (#49821)

Signed-off-by: Chenglun Hu <chenglunhu@gmail.com>
Signed-off-by: hclsys <chenglunhu@gmail.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
hcl
2026-10-01 23:35:58 +00:00
committed by GitHub
co-authored by Harry Mellor
parent d2125ea681
commit e35082e7b6
2 changed files with 61 additions and 7 deletions
+39 -2
View File
@@ -8,7 +8,12 @@ import pytest
from vllm.config.cache import CacheConfig
from vllm.config.scheduler import SchedulerConfig
from vllm.config.utils import get_hash_factors, hash_factors, normalize_value
from vllm.config.utils import (
get_attr_docs,
get_hash_factors,
hash_factors,
normalize_value,
)
# Helpers
@@ -114,7 +119,7 @@ def test_normalize_value_uuid_and_to_json():
[
(lambda x: x),
(type("CallableInstance", (), {"__call__": lambda self: 0}))(),
(lambda: (lambda: 0))(), # nested function instance
(lambda: lambda: 0)(), # nested function instance
],
)
def test_error_cases(bad):
@@ -190,6 +195,31 @@ def test_ir_config_hash_initializes_provider_and_tracks_implementation(monkeypat
assert config.compute_hash() != first_hash
def test_get_attr_docs_includes_inherited_fields():
"""get_attr_docs must collect attribute docstrings inherited from base
classes, not just those declared in the class's own body."""
@dataclass
class Base:
inherited: object = None
"""doc for inherited (base)."""
overridden: object = None
"""base version of overridden."""
@dataclass
class Derived(Base):
own: object = None
"""doc for own (derived)."""
overridden: object = None
"""derived override of overridden."""
docs = get_attr_docs(Derived)
assert docs["own"] == "doc for own (derived)."
assert docs["inherited"] == "doc for inherited (base)."
assert docs["overridden"] == "derived override of overridden."
def test_envs_compile_factors_stable():
"""Test that envs.compile_factors() hash is stable across fresh initializations.
@@ -325,3 +355,10 @@ print(hash_factors(envs.compile_factors()))
"HOME relocation changed the compile-cache env hash - a "
"location-only derived var is leaking into the key"
)
def test_get_attr_docs_rejects_non_class():
"""The annotation forbids it, but the runtime guard still protects
untyped callers, so keep asserting the documented TypeError."""
with pytest.raises(TypeError, match="Given object was not a class."):
get_attr_docs(object()) # type: ignore[arg-type]