-
Notifications
You must be signed in to change notification settings - Fork 218
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
WIP: stub generation #421
Merged
WIP: stub generation #421
Conversation
This file contains 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
eb8c7ee
to
edd4425
Compare
9f5259c
to
26b6f00
Compare
2b33cb1
to
7df32f1
Compare
7508fc4
to
0a82920
Compare
The ``__nb_signature__`` property of nanobind functions exposes: - how many overloads a function has - the function signature for each overload - the docstring for each overload (or ``None``) - the default arguments of each overload (if present), which are directly returned as Python objects. This leaves the complex and potentially ill-defined task of turning those Python objects into a valid Python expression to the consumer of this API. - The returned signature references the default arguments using substrings of the form '\0', '\1', etc.
…or outputs This changes the automatically generated type annotations for STL type casters so that an operation like ``` std::vector<int> f(std::vector<int> x) { return x } ``` is documented as ``` f(Sequence[int]) -> list[int] ``` This reflects that these are quite accommodating in terms of what they accept as inputs. The nanobind stub generator uses this information to furthermore generates automatic imports for the needed type annotations like ``typing.Sequence``.
db73871
to
c95e121
Compare
The old ``nb::raw_doc`` API could previously be used to override the docstring of an entire overload chain. This has the downside that it cannot easily be split into per-overload signatures and docstrings that are needed by the new stub generation tool. This commit removes ``nb::raw_doc`` and replaces it with a new annotation ``nb::signature`` that only overrides the function type signature of a single overload, while keeping the docstring separate. This is an API and ABI-breaking change.
76abb92
to
27ef69f
Compare
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.
This work-in-progress PR tracks progress towards a built-in stub generator. Please see issue #420 for discussion.