-
Notifications
You must be signed in to change notification settings - Fork 44
Support @overload decorator generation #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5a1e0ac
to
d705595
Compare
2b9a1b6
to
9408785
Compare
ba63325
to
68e80ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for generating @overload
decorators in Python stub files when multiple function or method signatures exist for the same name. The implementation automatically detects when there are multiple entries for the same function/method and generates appropriate @typing.overload
decorators, while also ensuring the typing
module is imported when needed.
- Converts single function/method storage to collections that support multiple signatures per name
- Adds automatic detection and generation of
@typing.overload
decorators - Implements conditional import of the
typing
module when overloads are present
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
pyo3-stub-gen/src/generate/variant_methods.rs | Updates return type to use IndexMap for grouping methods by name |
pyo3-stub-gen/src/generate/stub_info.rs | Adds overload tracking and converts function/method storage to support multiple signatures |
pyo3-stub-gen/src/generate/module.rs | Implements overload decorator generation and conditional typing import |
pyo3-stub-gen/src/generate/class.rs | Updates class method handling to support overloaded methods |
examples/pure/tests/test_python.py | Adds test cases for overloaded functions and methods |
examples/pure/src/lib.rs | Adds example implementations demonstrating overload functionality |
examples/pure/pure.pyi | Shows generated stub file with overload decorators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What have been done in this PR?
@overload
decorator for functions and methods.@overloaded
decorator when there are multiplePyFunctionInfo
orMethodInfo
for the same function/method (current main just picks the last submitted one).@overload
.import typing
if needed.