Commit Graph

991 Commits

Author SHA1 Message Date
Icxolu 31c4820010
deprecate `&PyModule` as `#[pymodule]` argument type (#3936)
* deprecate `&PyModule` as `#[pymodule]` argument type

* cleanup

* add ui tests

* fix deprecations in tests

* fix maturin and setuptools-rust starters

* run `deprecated` ui test only when `gil-refs` as disabled
2024-03-08 00:28:11 +00:00
Thomas Tanon fbd531195a
PyAddToModule: Properly propagate initialization error (#3919)
Better than panics
2024-03-06 18:20:02 +00:00
David Hewitt 57bbc32e7c
add `experimental-async` feature (#3931)
* add `experimental-async` feature

* gate async doctests on feature
2024-03-06 00:54:45 +00:00
Thomas Tanon fe84fed966
Allow inline struct, enum, fn and mod inside of declarative modules (#3902)
* Inline struct, enum, fn and mod inside of declarative modules

* remove news fragment

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-06 00:31:56 +00:00
Bruno Kolenbrander 4114dcb1a0
Thread pyo3's path through the builder functions (#3907)
* Thread pyo3's path through the builder functions

* preserve span of pyo3_path

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-04 07:54:04 +00:00
Icxolu 70a7aa808d
deprecate the use of `PyCell` in favor of `Bound` and `Py` (#3916)
* deprecate the use of `PyCell` in favor of `Bound` and `Py`

* update `FromPyObject` for `T: PyClass + Clone` impl

* move `PyCell` deprecation to the `gil-refs` feature gate and add a migration note
2024-03-03 14:47:25 +00:00
David Hewitt 2e56f659ed
split `PyCell` and `PyClassObject` concepts (#3917)
* add test for refguard ref counting

* split `PyCell` and `PyClassObject` concepts

* rework `create_cell` to `create_class_object`

* Apply suggestions from code review

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>

* review: Icxolu feedback

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-03-03 07:00:59 +00:00
Lily Foote 56683ed553
deprecate Py::as_ref (#3864)
* Deprecate Py::as_ref

* Reword as_ref deprecation note

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* Tidy up remaining uses of Py::as_ref

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* Pass hello into println! explicitly

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-29 07:15:34 +00:00
Matthew Neeley 68ec6de0c9
Use single-arg form of `#[pymodule]` function in docs and tests (#3899)
* Use single-arg form for `#[pymodule]` functions in docs and tests

* Update guide/src/function.md

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>

* Add test of two-argument module function

* Fix new test

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-02-28 22:36:50 +00:00
Matthew Neeley a15e4b1a11
Allow pymodule functions to take a single Bound<'_, PyModule> arg (#3905) 2024-02-27 22:24:14 +00:00
Lily Foote a3ad28b70c
Pymodule bound (#3897)
* 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>
2024-02-27 19:19:52 +00:00
Lily Foote 5c41ea0ade
Implement `From<Bound<'py, T>>` for PyErr (#3881)
* Implement `From<Bound<'py, T>>` for PyErr

* Replace PyErr::from_value_bound calls with .into

* Fix From<MyError> expected error message

* Add a trait bound to From<Bound<'py, T>> for PyErr
2024-02-26 23:14:41 +00:00
Icxolu 7c10ff4327
allow `Bound<'_, T>` in #[pymethods] `self` position (#3896)
* allow `Bound<'_, T>` in #[pymethods] `self` position

* rename `TryFromPyCell` -> `TryFromBoundRef`

* remove unneccessary unsafe
2024-02-25 07:13:36 +00:00
Thomas Tanon e0e3981e17
#[pymodule] mod some_module { ... } v3 (#3815)
* #[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>
2024-02-24 13:50:18 +00:00
Lily Foote e145ae851a
Update new_closure_bound closure signature (#3883)
* Update new_closure_bound closure signature

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>

* Use anonymous lifetimes in closure bounds

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* Take &Bound in PyCFunction closures

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-23 14:07:54 +00:00
Icxolu 4f8ee96881
fix `AsRef` and `Deref` impls on `Bound<T>` (#3879)
* fix `AsRef` and `Deref` of `Bound<T>` to `Bound<PyAny>`

* cleanup unnessesary `.as_any()` calls

* remove trait bound on `AsRef` impl

* add comment for `Deref` trait bound

* rename marker trait
2024-02-22 22:38:42 +00:00
David Hewitt 9e74c858c2
add `PyModule::new_bound` and `PyModule::import_bound` (#3775)
* add `PyModule::new` and `PyModule::import_bound`

* review: Icxolu feedback
2024-02-22 09:35:47 +00:00
Icxolu 61bc02d927
deprecate `PyCell::new` in favor of `Py::new` or `Bound::new` (#3872)
* 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>
2024-02-20 07:45:47 +00:00
Lily Foote a93900686e
Deprecate Py::into_ref (#3867)
* Migrate into_ref calls to Bound api

* Mark Py::into_ref as deprecated
2024-02-20 07:10:45 +00:00
Lily Foote 76dabd4e60
Replace as_ref(py) with Bound APIs (#3863) 2024-02-19 22:39:54 +00:00
David Hewitt 4efc4b82a3
ci: fix redundant import warnings on nightly (#3873) 2024-02-19 22:07:05 +00:00
Icxolu 4ce9c35983
port `Python::get_type` to `Bound` API (#3846)
* port `Python::get_type` to `Bound` API

* fix `is_subclass_and_is_instance` FIXME
2024-02-18 18:27:19 +00:00
David Hewitt f04ad56df4
implement `PyTypeMethods` (#3705)
* implement `PyTypeMethods`

* introduce `PyType` bound constructors

* `from_type_ptr_bound` instead of `from_type_ptr_borrowed`

* correct conditional code

* just make `from_type_ptr_bound` create an owned `Bound`

* correct docstrings

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>

* Rework as `PyType::from_borrowed_type_ptr`

* correct doc link to `from_borrowed_type_ptr`

Co-authored-by: Lily Foote <code@lilyf.org>

* remove unneeded lifetime name

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
Co-authored-by: Lily Foote <code@lilyf.org>
2024-02-18 03:07:48 +00:00
Lily Foote 0dd568d397
Use the new bound API instead of .as_ref(py) (#3853)
* 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
2024-02-18 00:09:56 +00:00
Lily Foote 940804fe0d
Pyerr value bound (#3820)
* 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
2024-02-17 00:27:45 +00:00
David Hewitt ec6d587218
support `Bound` for `classmethod` and `pass_module` (#3831)
* support `Bound` for `classmethod` and `pass_module`

* `from_ref_to_ptr` -> `ref_from_ptr`

* add detailed docs to `ref_from_ptr`
2024-02-16 00:36:11 +00:00
Icxolu f3ddd023c9
convert `PyBuffer` to `Bound` API (#3836) 2024-02-14 22:10:59 +00:00
Icxolu 0c12d9137f
port `Python::import` to `Bound` API (#3832)
* port `Python::import` to `Bound` API

* tidy up imports in tests/test_datetime_import.rs

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-14 00:24:37 +00:00
Icxolu fbfeb2ff03
update `#[derive(FromPyObject)]` to use `extract_bound` (#3828)
* update `#[derive(FromPyObject)]` to use `extract_bound`

* type inference for `from_py_with` using function pointers
2024-02-13 00:09:41 +00:00
David Hewitt 5b9b76fe58
add `_bound` constructors for datetime types (#3778)
* add `_bound` constructors for datetime types

* review: Icxolu feedback

* update uses of deprecated timezone_utc
2024-02-12 20:49:58 +00:00
Icxolu c359f5ca1d
deprecate `PyDict::new` constructor (#3823)
* deprecate `PyDict::new`

* update benchmarks

* convert `test_frompyobject`
2024-02-11 23:55:56 +00:00
David Hewitt 55488d3880
Merge pull request #3818 from davidhewitt/datetime-segv
fix segmentation fault when `datetime` module is invalid
2024-02-11 09:04:32 +00:00
David Hewitt 5b1104131f fix segmentation fault when `datetime` module is invalid 2024-02-11 02:44:31 +00:00
Icxolu e45fbe493c port `IntoPyDict` to `Bound` API 2024-02-10 15:47:26 +01:00
Icxolu 4d423b0c67 port `Python::run` to `Bound` API 2024-02-09 22:09:16 +01:00
Icxolu 33dc33ecec port `Python::eval` to `Bound` API 2024-02-09 17:52:00 +01:00
David Hewitt bcb7b88c23 ci: updates for rust 1.76 2024-02-08 21:13:58 +00:00
David Hewitt 030a618e0d
Merge pull request #3800 from snuderl/PyCFunction-bound-api
PyCFunction bound api
2024-02-06 18:28:40 +00:00
Blaž Šnuderl aa3c938b5e PyCFunction bound api 2024-02-06 18:44:53 +01:00
David Hewitt de93d15eeb ci: fix beta clippy `map_clone` warning 2024-02-05 07:57:27 +00:00
David Hewitt 76d1b34cd5 Revert "Merge pull request #3578 from davidhewitt/typed-helpers"
This reverts commit 7b07d6d21b, reversing
changes made to 99858236bd.
2024-02-03 20:56:23 +00:00
David Hewitt d8c5e7943c
Merge pull request #3790 from Icxolu/bool
add `Bound` constructor for `PyBool`
2024-02-03 13:10:30 +00:00
Icxolu af21a9dc74 add `Bound` constructor for `PyBool` 2024-02-03 12:06:50 +01:00
David Hewitt 8f8d4d33fa
Merge pull request #3776 from davidhewitt/bound-extract
migrate `FromPyObject` for `Bound` and `Py` to new APIs
2024-02-02 23:10:47 +00:00
David Hewitt a60c1821af implement `PyFunctionArgument` for `&Bound<T>` 2024-02-01 13:22:53 +00:00
David Hewitt 4c94be51a7 add `PyBytes::new_bound` 2024-02-01 08:52:28 +00:00
David Hewitt c47565666d add `PyString::new_bound` 2024-01-29 13:14:00 +00:00
David Hewitt eb8d11f42f
Merge pull request #3769 from davidhewitt/remove-test-pep-587
remove `test_pep_587`
2024-01-27 22:33:35 +00:00
David Hewitt 5ccc46e459 remove `test_pep_587` 2024-01-27 21:57:43 +00:00
David Hewitt eed196329d add list bound constructors 2024-01-27 21:12:55 +00:00