Commit Graph

6203 Commits

Author SHA1 Message Date
Bruno Kolenbrander 989d2c53ab
Fix non_local_definitions lint triggers (#3955) 2024-03-12 22:59:33 +00:00
Thomas Tanon 7cde95bba4
Documents experimental-declarative-modules feature (#3953)
* Documents experimental-declarative-modules feature

* More details on experimental-declarative-modules progress
2024-03-12 22:57:31 +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
Georg Brandl a7fa1bdf22
fix: remove "track_caller" cfg check (#3951)
This "cfg" value does not seem to exist (any more?), and #[track_caller]
is used a lot elsewhere without cfg_attr.

Found using cargo check -Zcheck-cfg.
2024-03-11 12:40:26 +00:00
acceptacross 93323bc922
chore: remove repetitive words (#3950)
Signed-off-by: acceptacross <csqcqs@gmail.com>
2024-03-11 10:15:03 +00:00
David Hewitt 67b1b35013
release: 0.21.0-beta.0 (#3944) 2024-03-10 22:16:18 +00:00
David Hewitt db0a98c040
ci: pin pytest < 8.1 (#3946) 2024-03-10 16:17:15 +00:00
David Hewitt 9145fcfe19
docs: major rewrite for Bound API (#3906)
* wip bound docs

* Update guide/src/python_from_rust/calling-existing-code.md

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

* continue to move and tidy up

* Apply suggestions from code review

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

* update URL

* complete python-from-rust.md

* progress on types.md; probably more to go

* update doctest paths

* review: Icxolu

* finish updating `types.md` to Bound API

* update remainder of the guide to Bound API

* Update guide/src/performance.md

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

* Update guide/src/types.md

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

* Update src/lib.rs

* review: Icxolu

* Update guide/src/python-from-rust.md

Co-authored-by: Adam Reichold <adamreichold@users.noreply.github.com>

* Update guide/src/async-await.md

Co-authored-by: Adam Reichold <adamreichold@users.noreply.github.com>

* review: adamreichold

---------

Co-authored-by: Lily Foote <code@lilyf.org>
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
Co-authored-by: Adam Reichold <adamreichold@users.noreply.github.com>
2024-03-10 15:51:51 +00:00
David Hewitt 75af678f43
docs: use kebab-case instead of snake_case for guide URLs (#3942)
* guide: use kebab-case instead of snake_case

* fixup doctest names

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

* review: Icxolu

* fix relative url

* also remap latest pyo3

* fixup python_from_rust

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-03-09 20:10:58 +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 14d1d2a9ee
docs: use `lychee` to check link URLs (#3941)
* guide: install `mdbook-linkcheck`

* use `shutil` to copy license files

* move from `mdbook-linkcheck` to `lychee`

* clean guide & doc build products before build

* fix more broken links

* review: mejrs
2024-03-08 14:10:47 +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
Thomas Tanon 0f7ddb19a5
PyPy: remove PyCode (PyCode_Type does not exist) (#3934) 2024-03-06 18:19:43 +00:00
Thomas Tanon d35f41e0bf
Chrono: allow deprecation warning until upgrading to 0.4.35+ (#3935)
* Chrono: allow deprecation warning until upgrading to 0.4.35+

Requiring 0.4.35 is blocked on MSRV (Chrono: 1.61, PyO3: 1.56)

* also allow deprecated chrono in example

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-06 17:49:43 +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
David Hewitt b08ee4b7e1
remove `gil-refs` feature from `full` feature (#3930) 2024-03-04 22:23:35 +00:00
Lily Foote 811a3e5d00
Add IntoIterator for &Bound types (#3923)
* Add IntoIterator for &Bound<'py, PyList>

* Add a test for Bound<'_, PyList>.into_iter

* Implement IntoIterator for more &Bound types

* Remove some explicit .iter() calls

* Implement IntoIterator for &Bound<'py, PyIterator>
2024-03-04 21:24:38 +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
Icxolu 00eb014623
docs: update Python function section of the guide (#3925)
* docs: update Python function section of the guide

* update `pass_module` types

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

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-03 09:15:46 +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 81be11e67a
docs: update Python modules section of the guide (#3924) 2024-03-02 22:55:05 +00:00
Lily Foote d94827720e
Delete duplicate test code (#3926)
These used to explicitly call `.iter()`, but that was removed in b65cbb9
to remove lints.
2024-03-02 22:53:28 +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
Icxolu 1d224610c3
docs: update `Python classes` section of the guide (#3914)
* docs: update `Python classes` section of the guide

* review feedback davidhewitt

* migration guide entry
2024-03-01 09:21:47 +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
David Hewitt a582fa0163
docs: update discord invite to permanent one (#3913) 2024-02-28 20:51:40 +00:00
Icxolu 55833365b5
seals `PyAnyMethods` and friends (#3909)
* seals `PyAnyMethods` and friends

This seals these new traits, preventing downstream
crates from implementing them on their types.
These traits are mainly a workaround for arbitrary
self receiver types, so this gives us more
flexibility if these need to be changed in the
future.

* move `PyResultExt` seal
2024-02-28 19:36:55 +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 93704047a5
store `Bound<T>` inside `PyRef` and `PyRefMut` (#3860)
* store `Bound<T>` inside `PyRef` and `PyRefMut`

* update `FromPyObject` for `PyRef` to use `extract_bound`

* review: Icxolu feedback
2024-02-27 18:56:22 +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
David Hewitt cd1c0dbf39
ci: move cross compile tests to their own jobs (#3887)
* ci: move cross compile tests to their own jobs

* don't run cross-compile jobs on regular PRs
2024-02-26 21:47:35 +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
David Hewitt 404161c969
ci: apply correct permissions for cache cleanup job (#3898) 2024-02-25 09:49:22 +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
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