* Support Bound in pymodule and pyfunction macros
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
* Remove spurious $ character
Co-authored-by: Matthew Neeley <mneeley@gmail.com>
* Rework PyCFunction::new_bound signatures
This allows us to remove the awkward `PyFunctionArgumentsBound` enum.
* Use BoundRef instead of BoundModule
* support argument deduction for `wrap_pyfunction_bound!`
* support `wrap_pyfunction!` with `Bound` input/output
* Fix docs link to `wrap_pyfunction_bound!`
* Revert back to wrap_pyfunction!
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Matthew Neeley <mneeley@gmail.com>
* #[pymodule] mod some_module { ... } v3
Based on #2367 and #3294
Allows to export classes, native classes, functions and submodules and provide an init function
See test/test_module.rs for an example
Future work:
- update examples, README and guide
- investigate having #[pyclass] and #[pyfunction] directly in the #[pymodule]
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Georg Brandl <georg@python.org>
* tests: group exported imports
* Consolidate pymodule macro code to avoid duplicates
* Makes pymodule_init take Bound<'_, PyModule>
* Renames #[pyo3] to #[pymodule_export]
* Gates #[pymodule] mod behind the experimental-declarative-modules feature
* Properly fails on functions inside of declarative modules
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Georg Brandl <georg@python.org>
* fix `either` feature conditional compilation, again
* test feature powerset in CI
* install `rust-src` for feature powerset tests
* review: adamreichold feedback
* Fix one more case of redundant imports.
* just check feature powerset for now
---------
Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
* deprecate `PyCell::new` in favor of `Py::new` or `Bound::new`
* update deprecation warning
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
* update `Py::extract` to use `extract_bound`
* update docstring of `FromPyObject`
* move `Option` conversions to new module & update
* move `Cell` conversions to new module & update
* make `Borrowed` ptr constructors public
* introduce `Bound::from_borrowed_ptr` constructors
* clippy `assert_eq` -> `assert`
* rerrange function order and correct docstrings
* port `PyObject::downcast` to `Bound` API
* relax traits bounds for unchecked variant in `Bound` API
* deprecate `Python::(checked_)cast_as`
* reword deprecation warning
* Use the new bound API instead of .as_ref(py)
* Move import into a nested scope
* Use to_cow instead of to_str for compatibility
`to_str` is not available before Python 3.10 on the limited api.
* Relax &self lifetimes
* Use Bound<'py, PyAny> in test Mapping signatures
* Use .as_bytes(py)
* Simplify ThrowCallback::throw signature
* Avoid .as_any call with Py api instead of Bound
* Implement PyErr::value_bound
* Use PyErr::value_bound in conversions
* Implement PyErr::from_value_bound
* Remove unnecessary clone
* Return a reference from PyErr::value_bound
* Avoid clone in PyErr::from_value_bound
* Use PyErr::from_value_bound instead of from_value
* Remove unnecessary .as_borrowed() calls
* Remove unused import
* Simplify UnraisableCapture.hook
* Use Bound::from_owned_ptr_or_opt in fn cause
* Update PyErrState::lazy to take Py<PyAny>
This is easier to work with elsewhere than `&PyAny` or
`Bound<'py, PyAny>`.
* Add Bound PyUnicodeDecodeError constructors
* Update PyErr::from_value_bound to take Bound
* Simplify PyErr::from_value
* Simplify PyErr::value
* Remove unnecessary reference
* Simplify Pyerr::cause implementation
* Simplify PyUnicodeDecodeError::new_bound