Skip to content

Commit 643aa95

Browse files
committed
handle OR and other checks
Signed-off-by: Raayan Dhar [email protected] <[email protected]>
1 parent 1bd728c commit 643aa95

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python/sglang/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,31 @@ def __call__(self, *args, **kwargs):
323323
module = self._load()
324324
return module(*args, **kwargs)
325325

326+
def __or__(self, other):
327+
self_type = self._load()
328+
if isinstance(other, LazyImport):
329+
other_type = other._load()
330+
elif isinstance(other, tuple):
331+
# Handle chaining: A | (B, C) -> (A, B, C)
332+
return (self_type,) + other
333+
else:
334+
other_type = other
335+
return (self_type, other_type)
336+
337+
def __ror__(self, other):
338+
self_type = self._load()
339+
if isinstance(other, LazyImport):
340+
other_type = other._load()
341+
elif isinstance(other, tuple):
342+
# Handle chaining: (A, B) | C -> (A, B, C)
343+
return other + (self_type,)
344+
else:
345+
other_type = other
346+
return (other_type, self_type)
347+
348+
def __instancecheck__(self, instance):
349+
return isinstance(instance, self._load())
350+
326351

327352
def download_and_cache_file(url: str, filename: Optional[str] = None):
328353
"""Read and cache a file from a url."""

0 commit comments

Comments
 (0)