From cdbb4879263091a4cba2943519ae158adf7f8668 Mon Sep 17 00:00:00 2001 From: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:56:30 -0800 Subject: [PATCH] refactor: read lazy attributes with getattr instead of a TypedDict wrapper (#50543) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/_lazy_imports.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/litellm/_lazy_imports.py b/litellm/_lazy_imports.py index 1ea4bb52668..2177edb4ca8 100644 --- a/litellm/_lazy_imports.py +++ b/litellm/_lazy_imports.py @@ -6,8 +6,6 @@ from collections.abc import Callable, Mapping from types import MappingProxyType, ModuleType from typing import TYPE_CHECKING, Final -from typing_extensions import ReadOnly, TypedDict - from ._lazy_imports_registry import LITELLM_ATTRIBUTES, UTILS_ATTRIBUTES if TYPE_CHECKING: @@ -61,22 +59,14 @@ def _cache(namespace: str, name: str, value: object) -> object: return value -class _AttributeView(TypedDict): - value: ReadOnly[object] - - -def _module_attribute(module: ModuleType, attr_name: str) -> object: - attribute: Final[_AttributeView] = {"value": getattr(module, attr_name)} - return attribute["value"] - - def _import(namespace: str, name: str, location: tuple[str, str]) -> object: cached: Final = _cached(namespace, name) if cached is not _NOT_LOADED: return cached module_path, attr_name = location module: Final[ModuleType] = importlib.import_module(module_path, package="litellm") - return _cache(namespace, name, _module_attribute(module, attr_name)) + attribute: Final[object] = getattr(module, attr_name) + return _cache(namespace, name, attribute) def _instance_of(class_name: str) -> Callable[[], object]: