[Bugfix] Override dunder methods of placeholder modules (#11882)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -7,9 +7,9 @@ import pytest
|
||||
import torch
|
||||
from vllm_test_utils import monitor
|
||||
|
||||
from vllm.utils import (FlexibleArgumentParser, StoreBoolean, deprecate_kwargs,
|
||||
get_open_port, memory_profiling, merge_async_iterators,
|
||||
supports_kw)
|
||||
from vllm.utils import (FlexibleArgumentParser, PlaceholderModule,
|
||||
StoreBoolean, deprecate_kwargs, get_open_port,
|
||||
memory_profiling, merge_async_iterators, supports_kw)
|
||||
|
||||
from .utils import error_on_warning, fork_new_process_for_each_test
|
||||
|
||||
@@ -323,3 +323,44 @@ def test_memory_profiling():
|
||||
del weights
|
||||
lib.cudaFree(handle1)
|
||||
lib.cudaFree(handle2)
|
||||
|
||||
|
||||
def test_placeholder_module_error_handling():
|
||||
placeholder = PlaceholderModule("placeholder_1234")
|
||||
|
||||
def build_ctx():
|
||||
return pytest.raises(ModuleNotFoundError,
|
||||
match="No module named")
|
||||
|
||||
with build_ctx():
|
||||
int(placeholder)
|
||||
|
||||
with build_ctx():
|
||||
placeholder()
|
||||
|
||||
with build_ctx():
|
||||
_ = placeholder.some_attr
|
||||
|
||||
with build_ctx():
|
||||
# Test conflict with internal __name attribute
|
||||
_ = placeholder.name
|
||||
|
||||
# OK to print the placeholder or use it in a f-string
|
||||
_ = repr(placeholder)
|
||||
_ = str(placeholder)
|
||||
|
||||
# No error yet; only error when it is used downstream
|
||||
placeholder_attr = placeholder.placeholder_attr("attr")
|
||||
|
||||
with build_ctx():
|
||||
int(placeholder_attr)
|
||||
|
||||
with build_ctx():
|
||||
placeholder_attr()
|
||||
|
||||
with build_ctx():
|
||||
_ = placeholder_attr.some_attr
|
||||
|
||||
with build_ctx():
|
||||
# Test conflict with internal __module attribute
|
||||
_ = placeholder_attr.module
|
||||
|
||||
Reference in New Issue
Block a user