Commit Graph

6162 Commits

Author SHA1 Message Date
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
David Hewitt 8f1b99e1e9
move chat discussions to Discord (#3892)
* move chat discussions to Discord

* guide: add some more signposting to the PyO3 Discord
2024-02-24 22:35:01 +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
Icxolu c06bb8f1f1
reexport `PyAnyMethods` and friends from `pyo3::types` (#3895)
* reexport `PyAnyMethods` and friends from `pyo3::types`

* remove duplicated imports
2024-02-24 13:46:59 +00:00
David Matos 0f29feca8f
Tidy up deprecation message on bound api (#3893) 2024-02-24 13:25:06 +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
David Hewitt fbf2e91914
macros: exact dependency on `pyo3-build-config` (#3889) 2024-02-23 12:30:46 +00:00
David Hewitt 11d143d0c9
release: 0.20.3 (#3890) 2024-02-23 12:30:38 +00:00
David Hewitt 9186da3892
ci: run fmt unconditionally (#3888) 2024-02-23 08:16:37 +00:00
Alexander Hill 0f92b670b2
docs: Add lcov / codecov options for nox coverage and update docs (#3825)
* docs: Clarify use of llmv-cov plugin

* Mention first-run

* Update Contributing.md

* Add options

* fix
2024-02-23 06:49:44 +00:00
Icxolu 6a815875a0
port `PyErr::from_type` to `Bound` API (#3885) 2024-02-23 06:31:51 +00:00
David Hewitt 5ca810236d
ci: rework GitHub caching strategy (#3886)
* ci: rework GitHub caching strategy

* clean up some more redundant imports flagged by nightly
2024-02-23 00:51:50 +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 8bd82da939
add missing deprecation for `PyDict::from_sequence` (#3884) 2024-02-22 22:52:25 +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
David Hewitt c4f66657c5
fix `either` feature conditional compilation, again (#3834)
* 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>
2024-02-22 08:05:37 +00:00
Lily Foote 5ddcd46980
Deprecate `py.from_owned_ptr` methods (#3875)
* Deprecate `py.from_owned_ptr` methods

* Refactor PyString.to_str

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

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-22 00:05:08 +00:00
Juniper Tyree 885883bf68
Add `Py::drop_ref` method (#3871)
* add Py::drop_ref method

* add changelog entry

* fix ffi import

* integrate review feedback

* Add a test

* Fix some build errors

* Fix some more build errors
2024-02-21 22:56:03 +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
David Hewitt 8ac7834f98
docs: update example for storing Py<T> in structs (#3876) 2024-02-20 07:08:49 +00:00
David Hewitt 7a03a6fe6d
ci: disable some benchmarks volatile on codspeed (#3861) 2024-02-19 22:40:08 +00:00
Lily Foote 76dabd4e60
Replace as_ref(py) with Bound APIs (#3863) 2024-02-19 22:39:54 +00:00
David Hewitt 9a36b50789
update `py.import` -> `py.import_bound` in benches (#3868) 2024-02-19 22:15:36 +00:00
David Hewitt 96b8c9facf
migrate some final `FromPyObject` implementations to the `Bound` API (#3869)
* 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
2024-02-19 22:14:26 +00:00
David Hewitt ececa86a7d
ci: cancel in-progress benches job on push (#3874) 2024-02-19 22:14:00 +00:00
David Hewitt 4efc4b82a3
ci: fix redundant import warnings on nightly (#3873) 2024-02-19 22:07:05 +00:00
Icxolu 0bb9cab6d3
port `PyComplex::from_complex` to `Bound` API (#3866)
* port `PyComplex::from_complex` to `Bound` API

* add `PyComplexMethods` to the prelude
2024-02-18 23:37:02 +00:00
David Hewitt a85ed34c45
add Bound API constructors from borrowed pointers (#3858)
* make `Borrowed` ptr constructors public

* introduce `Bound::from_borrowed_ptr` constructors

* clippy `assert_eq` -> `assert`

* rerrange function order and correct docstrings
2024-02-18 22:03:43 +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 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
Icxolu 1d295a12a0
port `PyObject::downcast` to `Bound` API (#3856)
* port `PyObject::downcast` to `Bound` API

* relax traits bounds for unchecked variant in `Bound` API

* deprecate `Python::(checked_)cast_as`

* reword deprecation warning
2024-02-18 01:11:43 +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 5f42c02e4f
Remove stray " character from docstring (#3852) 2024-02-17 17:04:35 +00:00
Icxolu c33d330b18
deprecate `PyFrozenSet::empty` (#3851) 2024-02-17 13:40:54 +00:00
Icxolu 1d8d81db2d
port `PyFrozenSetBuilder` to `Bound` API (#3850) 2024-02-17 12:21:41 +00:00
David Hewitt eb90b81d44
always use a Python iterator for sets and frozensets (#3849)
* always use a Python iterator for sets and frozensets

* add newsfragment
2024-02-17 10:57:53 +00:00
David Hewitt 65cf5808d9
docs: add note about mapping to dangling pointer with `Bound` API (#3805) 2024-02-17 10:35:28 +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
alm c24478e8bc
docs: fix link in Contributing.md (#3845) 2024-02-16 16:53:25 +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 05aedc9032
port `PyErr::warn` to `Bound` API (#3842)
* port `PyErr::new_type`

* port `PyErr::warn` and `PyErr::warn_explicit`
2024-02-16 00:12:43 +00:00
David Hewitt dc8b948201
add `PyBackedStr` and `PyBackedBytes` (#3802)
* add `PyBackedStr` and `PyBackedBytes`

* review: adamreichold feedback

* use `NonNull<[u8]>`

* clippy and newsfragment

* drop binding unused after refactoring

---------

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2024-02-15 07:58:20 +00:00
Icxolu f3ddd023c9
convert `PyBuffer` to `Bound` API (#3836) 2024-02-14 22:10:59 +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
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
Lily Foote a1e77c5a66
Document using as_borrowed in the Bound migration (#3833) 2024-02-13 23:30:16 +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