MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / get_impl

Function get_impl

openhands/app_server/utils/import_utils.py:43–78  ·  view source on GitHub ↗

Import and validate a named implementation of a base class. This function is an extensibility mechanism in OpenHands that allows runtime substitution of implementations. It enables applications to customize behavior by providing their own implementations of OpenHands base classes.

(cls: type[T], impl_name: str | None)

Source from the content-addressed store, hash-verified

41
42
43def get_impl(cls: type[T], impl_name: str | None) -> type[T]:
44 """Import and validate a named implementation of a base class.
45
46 This function is an extensibility mechanism in OpenHands that allows runtime
47 substitution of implementations. It enables applications to customize behavior by
48 providing their own implementations of OpenHands base classes.
49
50 The function ensures type safety by validating that the imported class is either
51 the same as or a subclass of the specified base class.
52
53 Args:
54 cls: The base class that defines the interface
55 impl_name: Fully qualified name of the implementation class, or None to use
56 the base class
57 e.g. 'openhands.server.conversation_service.'
58 'StandaloneConversationService'
59
60 Returns:
61 The implementation class, which is guaranteed to be a subclass of cls
62
63 Example:
64 >>> # Get default implementation
65 >>> ConversationService = get_impl(ConversationService, None)
66 >>> # Get custom implementation
67 >>> CustomService = get_impl(
68 ... ConversationService, 'myapp.CustomConversationService'
69 ... )
70
71 Common Use Cases:
72 - Server components (ConversationService, UserAuth, etc.)
73 - Storage implementations (SettingsStore, SecretsStore, etc.)
74 - Service integrations (GitHub, GitLab, Bitbucket, Azure DevOps services)
75
76 The implementation is cached to avoid repeated imports of the same class.
77 """
78 return _get_impl(cls, impl_name) # type: ignore

Callers 14

shared.pyFile · 0.90
load_server_configFunction · 0.90
get_user_authFunction · 0.90
get_for_userFunction · 0.90
injectMethod · 0.90
forgejo_service.pyFile · 0.90
get_github_service_implFunction · 0.90
get_gitlab_service_implFunction · 0.90
_get_user_providerFunction · 0.90

Calls 1

_get_implFunction · 0.85

Tested by 1

test_get_implFunction · 0.72