feat(stubgen): Add core stub generation library - ast based solution [1/3]#2721
Open
Rayahhhmed wants to merge 1 commit intofacebook:mainfrom
Open
feat(stubgen): Add core stub generation library - ast based solution [1/3]#2721Rayahhhmed wants to merge 1 commit intofacebook:mainfrom
Rayahhhmed wants to merge 1 commit intofacebook:mainfrom
Conversation
|
Diff from mypy_primer, showing the effect of this PR on open source code: pip (https://github.com/pypa/pip)
- WARN iterative_resolve_scc: SCC CalcId(pip._vendor.msgpack.fallback, /home/runner/work/pyrefly/pyrefly/primer_base/projects/pip/src/pip/_vendor/msgpack/fallback.py, KeyClassField(class1, _unpack)) exceeded 5 iterations; committing last answers
cloud-init (https://github.com/canonical/cloud-init)
+ WARN iterative_resolve_scc: SCC CalcId(cloudinit.sources.helpers.aliyun, /home/runner/work/pyrefly/pyrefly/primer_base/projects/cloud-init/cloudinit/sources/helpers/aliyun.py, Key::Definition(_process_dict_values 85:9-29)) exceeded 5 iterations; committing last answers
|
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D95793377. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Have added an AST-based
.pyistub generation from Python source.stubgen/emit.rs: Emits PEP484 stub syntax from ruff AST nodes, preserving source annotations verbatim via byte-range slicing (will improve on this heuristic in a separate PR)stubgen/visibility.rs: Filters exported names using__all__or public-name heuristics. The purpose of this file is to control if a function / method should be exposed in the stubs with this__all__scheme for public visibility.stubgen/mod.rs:generate_stub()entry point with 34 unit tests covering functions, classes, imports, overloads, type aliases, generics, and__all__filtering.Disclaimer: Used AI to generate the tests and to understand the structure of the codebase. AI was also used to understand the library details and help plan possible path ways with available API in the codebase so I don't have to go around looking for them.
No type inference yet! Unannotated items get
Anyor bare signatures. The inference layer will be added in a follow-up PR 👍Flow visualised for AST based parsing only (look below for code example):
flowchart LR A["source.py"] --> B["Ast::parse()"] B --> C["Definitions (resolve __all__)"] C --> D["VisibilityFilter"] D --> E["emit_stmt() per statement"] E --> F["stub.pyi"] style A fill:#2d3748,stroke:#e2e8f0,color:#e2e8f0 style F fill:#2d3748,stroke:#e2e8f0,color:#e2e8f0Test plan
cargo test -p pyrefly stubgenpassespython3 test.py --no-test --no-conformancepassesOutput diff:
Example python code (this is not commited, just a play example)
Issue
#2133
PR Train (If there is a better way to break this PR pls lmk 🙏) :