Extract source code of a class or callable object if possible. Args: object: The class or callable object to extract source code from Returns: Source code string if available, None otherwise
(self, object: Union[Type['T'], Callable])
| 355 | '<' in module_name) |
| 356 | |
| 357 | def get_source_code(self, object: Union[Type['T'], Callable]) -> Optional[str]: |
| 358 | """Extract source code of a class or callable object if possible. |
| 359 | |
| 360 | Args: |
| 361 | object: The class or callable object to extract source code from |
| 362 | |
| 363 | Returns: |
| 364 | Source code string if available, None otherwise |
| 365 | """ |
| 366 | try: |
| 367 | return inspect.getsource(object) |
| 368 | except (OSError, TypeError): |
| 369 | # Source code not available (e.g., dynamically generated, compiled, etc.) |
| 370 | return None |
| 371 | |
| 372 | def get_full_module_source(self, cls: Type) -> str: |
| 373 | """Get the full source code of the module containing the class, including all imports. |