Commit Graph

885 Commits

Author SHA1 Message Date
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
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
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 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
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
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 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
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 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
Icxolu c359f5ca1d
deprecate `PyDict::new` constructor (#3823)
* deprecate `PyDict::new`

* update benchmarks

* convert `test_frompyobject`
2024-02-11 23:55:56 +00:00
Lily Foote baf5c8ec0a
Implement PyErr::get_type_bound (#3819)
* Implement PyErr::get_type_bound

* Update docs for PyErr::get_type_bound

* Fix doctest for cloning PyErr

* Import the whole prelude in docs example

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

* Remove unnecessary self lifetime

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

* Remove more unnecessary self lifetimes

* Use variables to avoid dangling pointers

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

* Avoid using ffi in fn ptype on Py_3_12

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

* Add missing imports to fn ptype

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-11 21:07:28 +00:00
Jose c56cd3dd65
docs: clarify --pretty option to expand (#3810)
* Update debugging.md

Added clarification. --pretty no longer works, and it breaks even on nightly at least on cargo 1.78.0-nightly (cdf84b69d 2024-02-02) and
rustc 1.78.0-nightly (256b6fb19 2024-02-06).

* Update guide/src/debugging.md

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

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-11 20:52:49 +00:00
Jose f721c8c2b7
docs: fix link to README on building_and_distribution.md (#3809)
* Update building_and_distribution.md

Link to README not working.

* Update guide/src/building_and_distribution.md

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

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-02-11 20:52:14 +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
David Hewitt b7fb9e672e
Merge pull request #3782 from davidhewitt/type-check-bound
add `bound` method variants for `PyTypeInfo`
2024-02-09 20:22:44 +00:00
Icxolu 33dc33ecec port `Python::eval` to `Bound` API 2024-02-09 17:52:00 +01:00
David Hewitt 367eeaeeab add `bound` method variants for `PyTypeInfo` 2024-02-08 22:27:05 +00:00
David Hewitt 3541506a16 ci: allow some dead code warnings on nightly 2024-02-08 20:52:03 +00:00
David Hewitt 059e485a95
Merge pull request #3560 from Jgfrausing/patch-1
docs: Include section on how to disable signals in python
2024-02-06 09:01:17 +00:00
Jonatan G. Frausing b74d733244 docs: include section that disables signal in python 2024-02-06 08:33:44 +00:00
David Hewitt dd4df29bad docs: add `chrono` conversions to types table 2024-02-05 21:50:25 +00:00
David Hewitt ecb4ecbe22
Merge pull request #3789 from btel/patch-1
docs: add example for wrapping generic classes
2024-02-05 12:03:20 +00:00
Bartosz Telenczuk 64a6a02bf0 add example for wrapping generic classes 2024-02-05 11:00:09 +01: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 57735540e8
Merge pull request #3736 from Tpt/tpt/systemtime
Adds conversion between SystemTime and datetime
2024-02-01 14:05:51 +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 2f00eb1423 for now just change return type of `intern!` 2024-01-30 13:28:07 +00:00
David Hewitt aa139ad422 add `intern_bound!` macro 2024-01-30 10:58:19 +00:00
David Hewitt c47565666d add `PyString::new_bound` 2024-01-29 13:14:00 +00:00
David Hewitt 595ca4b3c1 Add `extract_bound` method to `FromPyObject` 2024-01-28 07:22:51 +00:00
David Hewitt ed7263faa2
Merge pull request #3767 from Icxolu/complex
implement `PyComplexMethods`
2024-01-27 22:06:02 +00:00
Icxolu 37e2a4d9c9 implement `PyComplexMethods` 2024-01-27 22:26:53 +01:00
David Hewitt 7927a2e211 add bench for tuple `get_borrowed_item` 2024-01-27 21:12:55 +00:00
David Hewitt 1657109ae0 documentation updates for `PyList::new_bound` 2024-01-27 21:12:55 +00:00
Tpt f83544910f Adds conversion between SystemTime and datetime 2024-01-27 17:43:51 +01:00
Icxolu f86053e2c2 implement `PyTracebackMethods` 2024-01-27 11:34:32 +01:00
Mate Kovacs f32becacc7 fix ugly example 2024-01-20 11:47:27 +09:00
David Hewitt d1b072222a
Merge pull request #3582 from mkovaxx/pyclass_complex_enum
Full ADT support with pyclass for complex enums
2024-01-19 14:17:28 +00:00
Mate Kovacs 3ed5ddb0ec feat: support pyclass on complex enums 2024-01-18 22:04:42 +09:00
David Hewitt 7366b1a386
Merge pull request #3730 from Tpt/chrono-tz
Conversion between chrono_tz::Tz and zoneinfo.ZoneInfo
2024-01-15 14:48:27 +00:00
David Hewitt 4504a7c96e fix some nightly lints 2024-01-12 2024-01-12 13:34:17 +00:00
Tpt 72f0c73925 Conversion between chrono_tz::Tz and zoneinfo.ZoneInfo 2024-01-08 15:19:49 +01:00
David Hewitt 50e33d86c7 add `call_bound` and `call_method_bound` 2024-01-03 13:24:14 +00:00
David Hewitt 53d25f7ff2 add new `PyTuple` constructors 2023-12-30 21:37:46 +00:00
David Hewitt a9f867c2cb begin drafting `Bound<T>` migration guide 2023-12-29 14:42:31 +00:00
David Hewitt 3da1aac2dd add `gil-refs` feature to aid migration 2023-12-29 14:42:31 +00:00
David Hewitt 46c3190a17 clean up remnants of deprecated & removed features 2023-12-29 13:36:46 +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
Adam Reichold 1b3dc6d7ac
Merge pull request #3661 from PyO3/iter-output-type
Replace (A)IterNextOutput by autoref-based specialization to allow returning arbitrary value
2023-12-20 12:53:42 +00:00
Adam Reichold 5528895f3e Relax the error type in the Result<Option<T>, E>> specializations for __(a)next__. 2023-12-20 13:12:16 +01:00
Adam Reichold a605308cee Add change log and migration guide entries. 2023-12-20 13:07:14 +01:00
David Hewitt bc87b7bac6 deprecate `PyTryFrom` and `PyTryInto` 2023-12-20 11:28:24 +00:00
Tpt 8b614745cf Adds std::duration::Duration from/to Python conversions 2023-12-20 08:57:26 +01: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 b0d4ef3525 Expand guide on async methods borrowing self. 2023-12-10 16:37:39 +01:00
Joseph Perez e73c795967
docs: fix typos 2023-12-07 10:10:15 +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 5c6d49084f remove all functionality deprecated in 0.19 2023-11-27 22:02:19 +00:00
Adam Reichold 1203921d5c
Merge pull request #3456 from aldanor/feature/either
Add conversion support for `either::Either`
2023-11-25 09:37:49 +00:00
David Hewitt bead83f4b0 docs: fixup docs for smallvec feature 2023-11-24 22:11:40 +00:00
Ivan Smirnov a75464ee26 add conversion support for `either::Either` 2023-11-24 22:09:34 +00:00
Joseph Perez 627841f1e2
feat: support `async fn` in macros with coroutine implementation 2023-11-22 20:25:36 +01:00
David Hewitt bd0174aa5d Change return types of `py.None()`, `py.NotImplemented()` and `py.Ellipsis()` to typed singletons 2023-11-17 16:16:19 +00:00
Surya 0ff84d250e
fix missing char conversion 2023-11-10 09:27:01 -05:00
Samuel Pastva 2fbc02d06c
Finish rename 2023-10-26 19:02:06 -05:00
Samuel Pastva fc787eabd2
Update guide/src/class.md
Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2023-10-26 18:58:43 -05:00
Samuel Pastva 48c90d9586 Add example of dynamic return type in the "Python classes" section of the guide. 2023-10-26 17:13:32 -05:00
David Hewitt 7534c31a6d
Note about `pyenv activate` and `pyenv virtualenv` commands
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2023-10-26 08:21:31 +01:00
David Hewitt 98346dd137 docs: improve detail around pyenv install 2023-10-25 23:29:20 +01:00
David Hewitt 2ca8e573a4 remove comparison to rust-cpython 2023-10-15 22:03:24 +01:00
David Hewitt e1d4173827 Fix bug in default implementation of `__ne__` 2023-10-11 09:48:06 +01:00
David Hewitt f335f42197
Merge pull request #3446 from davidhewitt/relax-import-check
relax multiple-import check to only prevent subinterpreters
2023-09-29 16:35:31 +00:00
SigureMo 25b2acb0eb
fix some dead links 2023-09-29 13:24:00 +08:00
David Hewitt f17e703167 return existing module on Python 3.9 and up 2023-09-23 11:13:39 +01:00
Jeff Schwab 535a255bae Fix a typo in a documentation page title 2023-09-21 21:11:27 +01:00
David Hewitt bcb01049cc
Merge pull request #3404 from davidhewitt/fix-dealloc
call PyObject_GC_Untrack before deallocating
2023-09-11 05:18:34 +00:00
David Hewitt e28403e772 call PyObject_GC_Untrack before deallocating 2023-09-09 22:29:58 +01:00
David Hewitt c7f834ad87 add migration guide entry for `PyDict::get_item` 2023-09-09 13:05:51 +01:00
Julian Hofer 6e24fb6643 guide: Add `playground.runnable` = false to book.toml 2023-09-05 22:28:43 +02:00
David Hewitt e67b283b25
Merge pull request #3358 from alex/ptr-unsafe-trait
fixes #3325 -- mark `AsPyPointer` as `unsafe trait`
2023-09-04 05:05:56 +00:00
David Hewitt 4c46d81afd simplify thread checker implementation 2023-09-03 14:15:26 +01:00
David Hewitt cc1aa598cd
Merge pull request #3411 from OliverFM/main
Update docs with fresher bazel example
2023-08-29 06:17:51 +00:00
oliver 9714f819f0 Update docs with fresher bazel example 2023-08-29 06:44:22 +01:00
Shahriar Heidrich 2855b9d508 Mention no subclassing of Python classes in docs 2023-08-28 12:34:13 +02:00