importing
Class info¶
🛈 DocStrings¶
Utilities for importing callables and classes from dotted paths.
get_module_source
¶
Get source code from a module or package.
Source code in src/llmling_agent/utils/importing.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
get_pyobject_members
¶
get_pyobject_members(
obj: type | ModuleType | Any, *, include_imported: bool = False
) -> Iterator[tuple[str, Callable[..., Any]]]
Get callable members defined in a Python object.
Works with modules, classes, and instances. Only returns public callable members (functions, methods, etc.) that are defined in the object's module unless include_imported is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
type | ModuleType | Any
|
Any Python object to inspect (module, class, instance) |
required |
include_imported
|
bool
|
Whether to include imported/inherited callables |
False
|
Yields:
| Type | Description |
|---|---|
tuple[str, Callable[..., Any]]
|
Tuples of (name, callable) for each public callable |
Example
class MyClass: ... def method(self): pass ... def _private(self): pass for name, func in get_pyobject_members(MyClass()): ... print(name) method
import my_module for name, func in get_pyobject_members(my_module): ... print(name) public_function
Source code in src/llmling_agent/utils/importing.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
import_callable
¶
Import a callable from a dotted path.
Supports both dot and colon notation: - Dot notation: module.submodule.Class.method - Colon notation: module.submodule:Class.method
Examples:
>>> import_callable("os.path.join")
>>> import_callable("llmling.testing:processors.failing_processor")
>>> import_callable("builtins.str.upper")
>>> import_callable("sqlalchemy.orm:Session.query")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Import path using dots and/or colon |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., Any]
|
Imported callable |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path cannot be imported or result isn't callable |
Source code in src/llmling_agent/utils/importing.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
import_class
¶
Import a class from a dotted path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dot-separated path to the class |
required |
Returns:
| Type | Description |
|---|---|
type
|
The imported class |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path is invalid or doesn't point to a class |
Source code in src/llmling_agent/utils/importing.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |