Skip to content

Commit 3990cb6

Browse files
committed
Fixed type errors in utility classes registry and singleton
1 parent 89113d8 commit 3990cb6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/guidellm/utils/registry.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from __future__ import annotations
1212

13-
from typing import Callable, ClassVar, Generic, TypeVar, cast
13+
from typing import Any, Callable, ClassVar, Generic, TypeVar, cast
1414

1515
from guidellm.utils.auto_importer import AutoImporterMixin
1616

@@ -19,7 +19,7 @@
1919

2020
RegistryObjT = TypeVar("RegistryObjT")
2121
"""Generic type variable for objects managed by the registry system."""
22-
RegisterT = TypeVar("RegisterT")
22+
RegisterT = TypeVar("RegisterT", bound=type) # Must be bound to type to ensure __name__ is available.
2323
"""Generic type variable for the args and return values within the registry."""
2424

2525

@@ -62,7 +62,7 @@ class TokenProposal(RegistryMixin):
6262
:cvar registry_populated: Track whether auto-discovery has completed
6363
"""
6464

65-
registry: ClassVar[dict[str, RegistryObjT] | None] = None
65+
registry: ClassVar[dict[str, Any] | None] = None
6666
registry_auto_discovery: ClassVar[bool] = False
6767
registry_populated: ClassVar[bool] = False
6868

@@ -209,6 +209,8 @@ def get_registered_object(cls, name: str) -> RegistryObjT | None:
209209
if name in cls.registry:
210210
return cls.registry[name]
211211

212-
lower_key_map = {key.lower(): key for key in cls.registry}
212+
for k, v in cls.registry.items():
213+
if name.lower() == k.lower():
214+
return v
213215

214-
return cls.registry.get(lower_key_map.get(name.lower()))
216+
return None # Not found

src/guidellm/utils/singleton.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def __init__(self, config_path: str):
3636
assert manager1 is manager2
3737
"""
3838

39+
_singleton_initialized: bool
40+
_init_lock: threading.Lock
41+
3942
def __new__(cls, *args, **kwargs): # noqa: ARG004
4043
"""
4144
Create or return the singleton instance.

0 commit comments

Comments
 (0)