@@ -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
327352def download_and_cache_file (url : str , filename : Optional [str ] = None ):
328353 """Read and cache a file from a url."""
0 commit comments