Gist 731c0162a924e371a567e83d242d7fa2
✓ Published0🌍 Public
深深度碎片
Last edited Aug 22, 2024
Created on Aug 22, 2024
This example shows a Python utility that generates `.pyi` stub files from source code by parsing and transforming Abstract Syntax Trees. The tool processes functions, classes, and decorators—specifically handling `@patch` and `@delegates`—ellipsizing bodies and cleaning annotations based on local type definitions. It uses the `ast` module for parsing, `inspect.signature` for extracting function parameters, and `fastcore` utilities like `@patch` and `delegates`. The script reads a Python file, walks the tree to collect class names, imports the module dynamically, and rewrites the tree before writing the stubbed output.
AI-generated description