Commit Graph

440 Commits

Author SHA1 Message Date
Bruno Kolenbrander 989d2c53ab
Fix non_local_definitions lint triggers (#3955) 2024-03-12 22:59:33 +00:00
David Hewitt 67b1b35013
release: 0.21.0-beta.0 (#3944) 2024-03-10 22:16:18 +00:00
Icxolu 908e661237
deprecate gil-refs in "self" position (#3943)
* deprecate gil-refs in "self" position

* feature gate explicit gil-ref tests

* fix MSRV

* adjust bracketing

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-09 09:52:12 +00:00
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
Icxolu 1c5265e1c2
deprecate `from_borrowed_ptr` methods (#3915)
* deprecate `from_borrowed_ptr` methods

This deprecates the methods on the `Python`
marker, aswell as `FromPyPointer`

* use `BoundRef` to defer ref cnt inc until after the error case
2024-03-01 20:51:53 +00:00
David Hewitt 8a12970c96
update `extract_argument` to use Bound APIs (#3708)
* update `extract_argument` to use `Bound` APIs

* tidy up borrow in macros expression

* update `trybuild` output

* more concise form for `DowncastError::new`

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

* use `Borrowed` instead of newtype

* use `Borrowed::from_ptr` methods in extract_argument

* update UI tests

* avoid double-negative `#[cfg]` clauses

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

* review: LilyFoote, Icxolu feedback

---------

Co-authored-by: Lily Foote <code@lilyf.org>
2024-02-28 19:36:20 +00:00
Matthew Neeley a15e4b1a11
Allow pymodule functions to take a single Bound<'_, PyModule> arg (#3905) 2024-02-27 22:24:14 +00:00
Icxolu 6f03a5464f
cleans up `PyCFunction::internal_new` (#3910)
This deduplicates some code around `PyCFunction::internal_new`
2024-02-27 22:15:35 +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
David Hewitt 8e2219b0d9
silence non-local-definitions nightly lint (#3901)
* silence non-local-definitions nightly lint

* add newsfragment

* add FIXMEs for `non_local_definitions`

* also allow `non_local_definitions` in doctests
2024-02-26 20:28:04 +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
David Hewitt fbf2e91914
macros: exact dependency on `pyo3-build-config` (#3889) 2024-02-23 12:30:46 +00:00
Lily Foote 22a23ffb31
Tidy some usage of `py.from_borrowed_ptr` and `py.from_borrowed_ptr_or_opt` (#3877)
* Tidy some usage of py.from_borrowed_ptr

* Add BoundRef::ref_from_ptr_or_opt
2024-02-22 23:06:55 +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
Lily Foote b4dc854585
Convert LazyTypeObject to use the Bound API (#3855) 2024-02-18 22:01:50 +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 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 9902633116
allow `from_py_with` on function args to take a `fn(&Bound) -> PyResult` (#3837) 2024-02-14 22:03:04 +00:00
David Hewitt f5eafe23f2
add maximum Python version check (#3821)
* add maximum Python version check

* restore dependency of `pyo3-macros-backend` on `pyo3-build-config`

* fix clippy-all noxfile job
2024-02-13 21:52:53 +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 0d4df9c19d adjust `FromPyObject` implementations to always use `'py` lifetime 2024-02-04 14:22:03 +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
Mate Kovacs 3ed5ddb0ec feat: support pyclass on complex enums 2024-01-18 22:04:42 +09:00
David Hewitt 4504a7c96e fix some nightly lints 2024-01-12 2024-01-12 13:34:17 +00:00
David Hewitt 46c3190a17 clean up remnants of deprecated & removed features 2023-12-29 13:36:46 +00:00
Adam Reichold 83697f0c62 Also replace IterANextOutput by autoref-based specialization to allow returning arbitrary values 2023-12-20 09:56:16 +01:00
Adam Reichold ca7d90dcf3 Replace IterNextOutput by autoref-based specialization to allow returning arbitrary values 2023-12-20 09:56:16 +01:00
Adam Reichold d75d4bdf81 Fix some holdouts from using argument holders for lifetime extensions. 2023-12-20 09:56:16 +01:00
Adam Reichold f03ccf204c Also apply holder lifetime extension to slot implementations. 2023-12-19 16:29:43 +01:00
Adam Reichold 27019b5523 Use local variables to extend lifetime of holder references. 2023-12-19 16:21:18 +01:00
David Hewitt 07726aefc4
Merge pull request #3609 from wyfo/async_receiver
feat: allow async methods to accept `&self`/`&mut self`
2023-12-07 07:38:25 +00:00
Joseph Perez f34c70c2da
feat: allow async methods to accept `&self`/`&mut self` 2023-12-07 07:42:10 +01:00
David Hewitt ed87637ebb replace `PyTryFrom` by splitting `PyTypeInfo` 2023-12-05 08:01:30 +03:00
Joseph Perez 8a674c2bd3
feat: add `coroutine::CancelHandle` 2023-12-04 07:46:51 +01:00
David Hewitt e62e6cad5d
Merge pull request #3603 from davidhewitt/0.19-deprecations
remove all functionality deprecated in 0.19
2023-11-28 06:47:30 +00:00
David Hewitt 53311a90eb
Merge pull request #3602 from davidhewitt/dead-kws
remove some unused keyword declarations
2023-11-28 06:45:43 +00:00
Alex Gaynor fae209419c fixes #3561 -- silence new clippy warning 2023-11-27 17:06:59 -05:00
David Hewitt 5c6d49084f remove all functionality deprecated in 0.19 2023-11-27 22:02:19 +00:00
David Hewitt e76797a1d6 remove some unused keyword declarations 2023-11-27 21:32:01 +00:00
Joseph Perez 781b9e3983
feat: add coroutine `__name__`/`__qualname__` and not-awaited warning 2023-11-25 21:51:20 +01:00
David Hewitt 9f66846238
Merge pull request #3595 from davidhewitt/ok-wrap
refactor `OkWrap` to not call `.into_py(py)`
2023-11-25 05:43:54 +00:00
David Hewitt c814078866 refactor `OkWrap` to not call `.into_py(py)` 2023-11-24 10:41:08 +00:00
David Hewitt 5ac56b8eb0 improve error for invalid `#[classmethod]` receivers 2023-11-24 03:24:46 +00:00