Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions components/src/dynamo/sglang/request_handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@
# SPDX-License-Identifier: Apache-2.0

from importlib import import_module
from typing import Any
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
# Declared, not imported at runtime. These mirror `_EXPORTS` below; without
# them the module-level `__getattr__` is the only thing that resolves the
# handlers, and hiding it from the type checker would make them all look
# missing.
from .embedding import EmbeddingWorkerHandler
from .handler_base import BaseGenerativeHandler, BaseWorkerHandler
from .image_diffusion import ImageDiffusionWorkerHandler
from .llm import DecodeWorkerHandler, DiffusionWorkerHandler, PrefillWorkerHandler
from .multimodal import (
MultimodalEncodeWorkerHandler,
MultimodalPrefillWorkerHandler,
MultimodalWorkerHandler,
)
from .video_generation import VideoGenerationWorkerHandler

_EXPORTS = {
# Base handlers
Expand All @@ -25,14 +41,22 @@
}


def __getattr__(name: str) -> Any:
if name not in _EXPORTS:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
# Hidden from the type checker on purpose. A module-level `__getattr__` tells
# mypy this package may have any attribute, so a typo such as
# `from ... request_handlers import DecodeWorkerHandlr` would check clean in
# every module that imports from here, and the real handlers resolve as `Any`.
# The `TYPE_CHECKING` block above declares them, so the checker gains their
# actual types and loses nothing.
if not TYPE_CHECKING:

def __getattr__(name: str) -> Any:
if name not in _EXPORTS:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

module = import_module(_EXPORTS[name], __name__)
value = getattr(module, name)
globals()[name] = value
return value
module = import_module(_EXPORTS[name], __name__)
value = getattr(module, name)
globals()[name] = value
return value


__all__ = [
Expand Down
Loading