You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2882: inspect: gate behind `experimental-inspect` feature r=davidhewitt a=davidhewitt
This is the last thing I want to do before preparing 0.18 release.
The `pyo3::inspect` functionality looks useful as a first step towards #2454. However, we don't actually make use of this anywhere within PyO3 yet (we could probably use it for better error messages). I think we also have open questions about the traits which I'd like to resolve before committing to these additional APIs. (For example, this PR adds `IntoPy::type_output`, which seems potentially misplaced to me, the `type_output` function probably wants to be on a non-generic trait e.g. `ToPyObject` or maybe #2316.)
As such, I propose putting these APIs behind an `experimental-inspect` feature gate for now, and invite users who find them useful to contribute a finished-off design.
Co-authored-by: David Hewitt <[email protected]>
Copy file name to clipboardexpand all lines: guide/src/features.md
+6
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,12 @@ If you do not enable this feature, you should call `pyo3::prepare_freethreaded_p
51
51
52
52
## Advanced Features
53
53
54
+
### `experimental-inspect`
55
+
56
+
This feature adds the `pyo3::inspect` module, as well as `IntoPy::type_output` and `FromPyObject::type_input` APIs to produce Python type "annotations" for Rust types.
57
+
58
+
This is a first step towards adding first-class support for generating type annotations automatically in PyO3, however work is needed to finish this off. All feedback and offers of help welcome on [issue #2454](https://github.com/PyO3/pyo3/issues/2454).
59
+
54
60
### `macros`
55
61
56
62
This feature enables a dependency on the `pyo3-macros` crate, which provides the procedural macros portion of PyO3's API:
Copy file name to clipboardexpand all lines: guide/src/python_typing_hints.md
+2
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@ PyO3 provides an easy to use interface to code native Python libraries in Rust.
4
4
5
5
Currently the best solution for the problem is to manually maintain `*.pyi` files and ship them along with the package.
6
6
7
+
There is a sketch of a roadmap towards completing [the `experimental-inspect` feature](./features.md#experimental-inspect) which may eventually lead to automatic type annotations generated by PyO3. This needs more testing and implementation, please see [issue #2454](https://github.com/PyO3/pyo3/issues/2454).
8
+
7
9
## Introduction to `pyi` files
8
10
9
11
`pyi` files (an abbreviation for `Python Interface`) are called "stub files" in most of the documentation related to them. A very good definition of what it is can be found in [old MyPy documentation](https://github.com/python/mypy/wiki/Creating-Stubs-For-Python-Modules):
0 commit comments