Recursively explore a module and print all public exported items. Args: module: The module or object to explore indent: Current indentation level (for pretty printing) visited: Set[int] = set()
(
module: Any, indent: int = 0, visited: set[int] | None = None
)
| 40 | |
| 41 | |
| 42 | def explore_module( |
| 43 | module: Any, indent: int = 0, visited: set[int] | None = None |
| 44 | ) -> list[str]: |
| 45 | """ |
| 46 | Recursively explore a module and print all public exported items. |
| 47 | |
| 48 | Args: |
| 49 | module: The module or object to explore |
| 50 | indent: Current indentation level (for pretty printing) |
| 51 | visited: Set[int] = set() |
| 52 | """ |
| 53 | if visited is None: |
| 54 | visited = set() |
| 55 | |
| 56 | # Skip if we've already visited this object |
| 57 | if id(module) in visited: |
| 58 | return [] |
| 59 | |
| 60 | visited.add(id(module)) |
| 61 | |
| 62 | results: list[str] = [] |
| 63 | # Get all attributes of the module |
| 64 | for name, obj in inspect.getmembers(module): |
| 65 | # Skip private/special attributes (starting with _) |
| 66 | if name.startswith("_"): |
| 67 | continue |
| 68 | |
| 69 | # Create indentation string |
| 70 | indent_str = " " * indent |
| 71 | |
| 72 | # Print the current item |
| 73 | results.append(f"{indent_str}{name}") |
| 74 | |
| 75 | # Recursively explore if it's a module, class, or other container type |
| 76 | if inspect.ismodule(obj) and obj.__name__.startswith(module.__name__): |
| 77 | # Only recurse into submodules of the original module |
| 78 | results.extend(explore_module(obj, indent + 1, visited)) |
| 79 | |
| 80 | return results |
searching dependent graphs…