util
call_method ¶
call_method(obj: RuntimeValue, name: str, args: tuple[RuntimeValue, ...] = (), kwargs: dict[str, RuntimeValue] | None = None) -> RuntimeValue
Call a method with the given name on the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to call the method on. |
required |
name
|
str
|
The name of the method to call. |
required |
args
|
tuple
|
The positional arguments to pass to the method. |
()
|
kwargs
|
dict
|
The keyword arguments to pass to the method. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
RuntimeValue
|
The result of calling the method. |
Source code in objinspect/util.py
call_method_async
async
¶
call_method_async(obj: RuntimeValue, name: str, args: tuple[RuntimeValue, ...] = (), kwargs: dict[str, RuntimeValue] | None = None) -> RuntimeValue
Call a method with the given name on the given object and await when needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to call the method on. |
required |
name
|
str
|
The name of the method to call. |
required |
args
|
tuple
|
The positional arguments to pass to the method. |
()
|
kwargs
|
dict
|
The keyword arguments to pass to the method. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
RuntimeValue
|
The result of calling the method. |
Source code in objinspect/util.py
get_uninherited_methods ¶
Get the methods of a class that are not inherited from its parent classes.
Source code in objinspect/util.py
create_function ¶
create_function(name: str, args: dict[str, ArgumentDef], body: str | list[str], globs: dict[str, RuntimeValue], return_type: TypeAnnotation = EMPTY, docstring: str | None = None) -> Callable[..., RuntimeValue]
Create a function with the given name, arguments, body, and globals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the function. |
required |
args
|
dict
|
A dictionary mapping argument names to tuples of the argument type and default value. |
required |
body
|
str | list
|
The body of the function. If a string, it will be split by newlines. |
required |
globs
|
dict
|
The globals to use when executing the function. |
required |
return_type
|
Any
|
The return type of the function. |
EMPTY
|
docstring
|
str
|
The docstring of the function. |
None
|
Example
Source code in objinspect/util.py
colored_type ¶
Return a colored string representation of a type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
type
|
The type to format. |
required |
style
|
TextStyle
|
The text style (color) to apply. |
required |
simplify
|
bool
|
Whether to simplify the type name. Defaults to True. |
True
|