Spaces:
Configuration error
Configuration error
Download openhands/utils/import_utils.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 634 Bytes
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/utils/import_utils.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/openhands/utils/import_utils.py
-
curl -L -o import_utils.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/openhands/utils/import_utils.py
634 Bytes
| import importlib | |
| from typing import Type, TypeVar | |
| T = TypeVar('T') | |
| def import_from(qual_name: str): | |
| """Import the value from the qualified name given""" | |
| parts = qual_name.split('.') | |
| module_name = '.'.join(parts[:-1]) | |
| module = importlib.import_module(module_name) | |
| result = getattr(module, parts[-1]) | |
| return result | |
| def get_impl(cls: Type[T], impl_name: str | None) -> Type[T]: | |
| """Import a named implementation of the specified class""" | |
| if impl_name is None: | |
| return cls | |
| impl_class = import_from(impl_name) | |
| assert cls == impl_class or issubclass(impl_class, cls) | |
| return impl_class | |