Commit Graph

1057 Commits

Author SHA1 Message Date
David Hewitt a4aea230ed
fix compile error for multiple async method arguments (#4035) 2024-04-02 17:43:51 +00:00
Icxolu 8f87b8636d
refactor `#[setter]` argument extraction (#4002) 2024-04-01 12:10:18 +00:00
Weijie Guo 74d9d23ba0
async method should allow args not only receiver (#4015)
* async method should allow args not only receiver

* add changelog md
2024-03-30 08:48:19 +00:00
David Hewitt cf74624de9
refactor to remove add_to_module functions from generated code (#4009)
* refactor to remove add_to_module functions from generated code

* mrsv, newsfragment

* clippy
2024-03-29 11:54:33 +00:00
Icxolu dd1710256d
use `extract_argument` for `#[setter]` extraction (#3998)
* use `extract_argument` for `#[setter]` extraction

* add newsfragment
2024-03-27 15:41:04 +00:00
Icxolu 35faeff6f1
handle `#[pyo3(from_py_with = "")]` in `#[setter]` methods (#3995)
* handle `#[pyo3(from_py_with = "")]` in `#[setter]` methods

* add newsfragment
2024-03-26 18:53:11 +00:00
David Hewitt d0f5b6af46
ci: updates for Rust 1.77 (#3978)
* ci: updates for Rust 1.77

* move `SendablePtr` inside of test which uses it
2024-03-22 20:43:23 +00:00
David Hewitt 351c6a0a49
deprecate optional GIL Ref in function argument (#3975) 2024-03-21 07:24:40 +00:00
David Hewitt 870a4bb20d
deprecate GIL refs in function argument (#3847)
* deprecate GIL Refs in function arguments

* fix deprecated gil refs in function arguments

* add notes on deprecations limitations to migration guide

* Apply suggestions from code review

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

* review: Icxolu

* fix proto method extract failure for option

* fix gil refs in examples

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-03-20 22:35:08 +00:00
Icxolu 2736cf670c
deprecate gil-refs in `from_py_with` (Part 2) (#3972)
* deprecate `from_py_with` in `#[derive(FromPyObject)]` (NewType)

* deprecate `from_py_with` in `#[derive(FromPyObject)]` (Enum, Struct)
2024-03-20 09:27:38 +00:00
David Hewitt 02e188e4b4
adjust path for GIL Refs deprecation warnings (#3968) 2024-03-19 21:08:20 +00:00
Icxolu b06e95727b
deprecate gil-refs in `from_py_with` (#3967)
* deprecate gil-refs in `from_py_with`

* review feedback davidhewitt
2024-03-19 08:58:41 +00:00
David Hewitt dcba984b51
deprecate `GILPool` (#3947)
* deprecate `GILPool`

* review: adamreichold

* fix deprecation warnings in tests
2024-03-15 10:25:27 +00:00
Icxolu ee89b2e8e2
deprecate `wrap_pyfunction` with `py` argument (#3954)
* deprecate `wrap_pyfunction` with `py` argument

The Python token in `wrap_pyfunction` is not handled automatically by
`WrapPyFunctionArg`, for backwards compatibility. This uses deref
specialization to deprecate this variant.

* merge `Extractor`s

* add deprecation ui test, revert closure variant due to test failure

* fix nightly
2024-03-12 22:57:03 +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
David Hewitt 770d9b7f01
add `FromPyObjectBound` trait for extracting `&str` without GIL Refs (#3928)
* add `FromPyObjectBound` adjustment for `&str` without GIL Refs

* review: alex, Icxolu feedback

* add newsfragment

* add newsfragment for `FromPyObject` trait change

* make some examples compatible with abi3 < 3.10

* seal `FromPyObjectBound`

* fixup chrono_tz conversion
2024-03-08 07:43:48 +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
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
David Hewitt 5f320d7a04
Merge pull request #3765 from davidhewitt/remove-py-newref
remove internal uses of `_Py_NewRef`
2024-01-27 13:35:29 +00:00
David Hewitt 87e0610b58 remove internal uses of `_Py_NewRef` 2024-01-27 12:07:46 +00:00
Icxolu 7fddd983b4 update `test_compile_error` ui test output 2024-01-27 12:37:26 +01: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 50e33d86c7 add `call_bound` and `call_method_bound` 2024-01-03 13:24:14 +00:00
David Hewitt 823b5feed3 improve tuple methods test coverage 2023-12-30 21:37:46 +00:00
David Hewitt 53d25f7ff2 add new `PyTuple` constructors 2023-12-30 21:37:46 +00:00
David Hewitt 375e3d4eee implement `PyTupleMethods` 2023-12-30 21:37:46 +00:00
Alex Gaynor 54390bc50b
Merge pull request #3712 from alex/binops
add PyAnyMethods for binary operators
2023-12-30 13:56:45 +00:00
Alex Gaynor 339660c117 add PyAnyMethods for binary operators
also pow

fixes #3709
2023-12-29 18:45:18 -05:00
David Hewitt e852a4b502 be more lax with ordering in `invalid_result_conversion` ui test 2023-12-29 22:06:33 +00:00
David Hewitt 3da1aac2dd add `gil-refs` feature to aid migration 2023-12-29 14:42:31 +00:00
David Hewitt e42d8cf612 ci: updates for Rust 1.75 2023-12-29 13:36:46 +00:00
Adam Reichold f37c682f8c
Merge pull request #3700 from davidhewitt/super-bound
introduce `PySuper::new_bound`
2023-12-25 09:48:39 +00:00
David Hewitt d9cc0c0f24 introduce `PySuper::new_bound` 2023-12-24 20:04:15 +00:00
David Hewitt 877e34ac86 implement `PyErr::write_unraisable_bound` 2023-12-24 19:35:29 +00:00
Adam Reichold 4dc6c1643e Turn calls of __traverse__ into no-ops for unsendable pyclass if on the wrong thread
Adds a "threadsafe" variant of `PyCell::try_borrow` which will fail instead of
panicking if called on the wrong thread and use it in `call_traverse` to turn GC
traversals of unsendable pyclasses into no-ops if on the wrong thread.

This can imply leaking the underlying resource if the originator thread has
already exited so that the GC will never run there again, but it does avoid hard
aborts as we cannot raise an exception from within `call_traverse`.
2023-12-23 15:01:08 +01:00
David Hewitt 0f242c399d make `DowncastError` and `DowncastIntoError` public 2023-12-21 13:03:59 +00:00
Adam Reichold ca7d90dcf3 Replace IterNextOutput by autoref-based specialization to allow returning arbitrary values 2023-12-20 09:56:16 +01:00
David Hewitt 1451418ee4 Add `Py2` variants of `PyDowncastError` 2023-12-19 20:59:57 +00:00
Adam Reichold 416d3c488f Rename name to qualname and full_name to name to better match Python 2023-12-19 16:51:24 +01:00
Adam Reichold ced97f80d1 Transition is_true to is_truthy to clarify that the test is not based on identity with or equality to the True singleton. 2023-12-16 14:04:37 +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 2ca9f59d6f
refactor: drop futures_util dependency 2023-12-04 18:56:34 +01:00
Joseph Perez 8a674c2bd3
feat: add `coroutine::CancelHandle` 2023-12-04 07:46:51 +01:00
David Hewitt 81ad2e8bab
Merge pull request #3598 from davidhewitt/clippy-beta
ci: run beta clippy as an allowed-to-fail job
2023-11-29 06:47:21 +00:00
David Hewitt cf67c2ce46 fix test-serde beta clippy warning 2023-11-28 07:29:45 +00:00
David Hewitt 5c6d49084f remove all functionality deprecated in 0.19 2023-11-27 22:02:19 +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