extended_data.primitives.introspection¶
This module provides utilities for inspecting the call stack and methods of classes.
It includes functions to get the caller’s name, filter methods, and retrieve available methods and their docstrings for a class.
Module Contents¶
Functions¶
Gets the name of the caller function. |
|
Generate a unique signature for an object based on its class and module. |
|
Filters out private methods from a list of method names. |
|
Gets available methods and their docstrings for a class. |
|
Extract existing input details from a method’s docstring. |
|
Update the docstring with new input definitions. |
|
Checks if the current Python version is at least the specified version. |
API¶
- extended_data.primitives.introspection.get_caller() str¶
Gets the name of the caller function.
Returns: str: The name of the caller function.
- extended_data.primitives.introspection.get_unique_signature(obj: Any, delim: str = '/') str¶
Generate a unique signature for an object based on its class and module.
Args: obj (Any): The object to generate a signature for. delim (str): The delimiter to use between the module and class names. Defaults to “/”.
Returns: str: A unique signature string for the object.
- extended_data.primitives.introspection.filter_methods(methods: list[str]) list[str]¶
Filters out private methods from a list of method names.
Args: methods (list[str]): The list of method names to filter.
Returns: list[str]: The filtered list of method names.
- extended_data.primitives.introspection.get_available_methods(cls: type[Any]) dict[str, str | None]¶
Gets available methods and their docstrings for a class.
An “available method” is a public method that:
Does not contain ‘__’ in its name.
Belongs to the same module as the class.
Does not have ‘NOPARSE’ in its docstring.
Args: cls (type[Any]): The class to inspect.
Returns: dict[str, str | None]: A dictionary of method names and their docstrings.
- extended_data.primitives.introspection.get_inputs_from_docstring(docstring: str) dict[str, dict[str, str]]¶
Extract existing input details from a method’s docstring.
This function parses a docstring to identify inputs defined with specific properties: name, required, and sensitive. The extraction is case-insensitive, and the results are returned as a dictionary with input names as keys (lowercase) and their properties as values.
Args: docstring (str): The docstring to parse for input definitions.
Returns: A dictionary where each key is an input name (in lowercase), and the value is another dictionary containing:
- "required": Whether the input is required ("true" or "false") - "sensitive": Whether the input is sensitive ("true" or "false")Example: For a docstring containing::
env=name: API_KEY, required: true, sensitive: false env=name: DB_PASSWORD, required: true, sensitive: true The output will be:: { "api_key": {"required": "true", "sensitive": "false"}, "db_password": {"required": "true", "sensitive": "true"} }
- extended_data.primitives.introspection.update_docstring(original_docstring: str, new_inputs: dict[str, dict[str, str]]) str¶
Update the docstring with new input definitions.
Args: original_docstring (str): The original docstring to update. new_inputs (dict[str, dict[str, str]]): A dictionary of new inputs to add to the docstring.
Returns: str: The updated docstring with new inputs.
- extended_data.primitives.introspection.current_python_version_is_at_least(minor: int, major: int = 3) bool¶
Checks if the current Python version is at least the specified version.
Args: minor (int): The minimum minor version. major (int, optional): The minimum major version. Defaults to 3.
Returns: bool: True if the current Python version is at least the specified version, False otherwise.