You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #454 introduces a context manager for optional imports. Once the connections branch is merged in to main this should be expanded to the optional transport imports as well.
In utils.py
@contextmanagerdefoptional_dependency(*names: str) ->Generator[None, None, None]:
"""Skip the imports in the block if one of the given packages isn't installed. Example:: with optional_dependency("httpx"): from .http_connection import HTTPConnection as HTTPConnection Args: names: The packages that the block may be missing Raises: ModuleNotFoundError: If a module other than the given packages is missing """try:
yieldexceptModuleNotFoundErrorase:
ife.nameisNoneore.name.split(".")[0] notinnames:
raise
Activity