Commit Graph

995 Commits

Author SHA1 Message Date
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
David Hewitt 5ac56b8eb0 improve error for invalid `#[classmethod]` receivers 2023-11-24 03:24:46 +00:00
David Hewitt aba3a3552d remove type_is_pymodule 2023-11-22 21:30:10 +00:00
David Hewitt 69870d2298
Merge pull request #3540 from wyfo/coroutine
feat: support `async fn` in macros with coroutine implementation
2023-11-22 19:52:15 +00:00
David Hewitt 3f0dfa9698
Merge pull request #3587 from wyfo/classmethod_into
feat: allow classmethods to receive `Py<PyType>`
2023-11-22 19:34:19 +00:00
Joseph Perez 627841f1e2
feat: support `async fn` in macros with coroutine implementation 2023-11-22 20:25:36 +01:00
Joseph Perez 744de3a142
feat: allow `classmethod`/`pass_module` to receive owned types
This is necessary for async functions
2023-11-22 07:45:59 +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
David Hewitt 29ad73b6d5 ci: updates for rust 1.74 2023-11-16 16:06:01 +00:00
David Hewitt cac95f31c7 add Py2 as an internal API for optimization and dogfooding 2023-10-13 08:10:37 +02:00
David Hewitt b73c06948c
Merge pull request #3504 from davidhewitt/classmethod-receiver
emit helpful error hint for classmethod with receiver
2023-10-10 21:35:34 +00:00
David Hewitt 6c90325a1c deprecate undocumented `#[__new__]` form of `#[new]` 2023-10-10 08:47:03 +01:00
David Hewitt ddc04ea093 emit helpful error hint for classmethod with receiver 2023-10-10 06:30:19 +01:00
David Hewitt 1158c08f42 error on passing arguments to `#[new]` and similar attributes 2023-10-08 21:31:59 +01:00
mejrs d6e22a9972 Only run invalid_result_conversion on linux 2023-10-08 04:23:05 +02:00
David Hewitt a1d333a563 emit compile errors on macros inside `#[pymethods]`
Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2023-10-02 22:15:29 +01:00
David Hewitt 7d486bb72a tests/common.rs -> src/tests/common.rs 2023-09-24 13:34:53 +01:00
David Hewitt c8f82be32c add assert_warnings test helper 2023-09-23 13:14:18 +01:00
David Hewitt 5798caf1f8 better `Some`-wrapping for default arguments 2023-09-21 21:14:44 +01:00
David Hewitt 8a60540e25 amend code for `PyDict::get_item` change 2023-09-09 12:23:06 +01:00
David Hewitt 4c46d81afd simplify thread checker implementation 2023-09-03 14:15:26 +01:00
David Hewitt a5d0a16b21 ci: updates for Rust 1.72 2023-08-25 12:30:34 +01:00
DataTriny 6c70db1e0b Test renaming rules 2023-08-16 18:24:19 +02:00
DataTriny f02fe9478d
Make rename_all accept a renaming rule, allow applying it to classes as well 2023-08-15 10:15:48 +02:00
DataTriny 57505cb1a1
Fix tests 2023-08-13 18:54:55 +02:00
David Hewitt 64adab1a76 add as_ptr and into_ptr inherent methods 2023-08-11 10:49:42 +01:00
David Hewitt c1126740c5 fix compile failure for getter with return lifetime of self 2023-07-29 21:20:10 +01:00
David Hewitt a15614844d add PyErr::display 2023-07-24 22:14:55 +01:00
David Hewitt 45ff25cd2a clippy: deny / fix used-underscope-binding lint 2023-07-16 20:49:45 +01:00
David Hewitt b65cbb958b ci: updates for rust 1.71 2023-07-14 12:10:37 +01:00
David Hewitt 56b7c38e24 improve error span for mutable access to `#[pyclass(frozen)]` 2023-07-11 22:34:53 +01:00
Alex Gaynor f39eb9e229
Resolve nightly clippy warning in test_field_cfg 2023-07-11 05:55:57 -04:00
David Hewitt bf2f441567 prefer inner / _private naming 2023-07-04 21:03:24 +01:00
Alex Gaynor 0b78bb851e
Allow `#[new]` to return existing instances
fixes #2384
2023-07-02 19:57:53 -04:00
mejrs 51a6863440 Give a better error message for Python in traverse 2023-06-19 23:25:51 +02:00
David Hewitt 4f3fcdbf0f remove all functionality deprecated in PyO3 0.18 2023-06-13 22:27:43 +01:00
Adam Reichold 0d30bb7d3d Bump Rust edition to 2021 and make current Clippy happy. 2023-06-07 21:15:38 +02:00
bors[bot] e1f028f3e5
Merge #3209
3209: Remove the conditional compilation flags which are made redundant  by the MSRV bump r=davidhewitt a=adamreichold



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-06-05 14:09:05 +00:00
Adam Reichold eb292711a7 Drop test indirection required only until Rust 1.54. 2023-06-05 12:43:15 +02:00
Adam Reichold b49e401319 Remove unmatched cfg and unused rustup component. 2023-06-05 09:36:13 +02:00
bors[bot] dbf7b233aa
Merge #3203
3203: support ordering magic methods for `#[pyclass]` r=adamreichold a=davidhewitt

Closes #2089 

This adds `__lt__`, `__le__`, `__eq__`, `__ne__`, `__gt__`, and `__ge__` as per the Python implementations of what we call `__richcmp__`.

There's a UI test confirming that the user cannot implement split forms and `__richcmp__` simultaneously.

There's also a benchmark comparing implementing these split methods against using `__richcmp__`. I couldn't see a meaningful performance difference, so I'm tempted to deprecate `__richcmp__`, given that's not a magic method which exists in Python. Potentially we can provide options such as the opt-in `#[pyclass(eq, ord)]` to avoid boilerplate for people who don't want to implement six different methods.



Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-06-05 07:13:23 +00:00
David Hewitt 5bc3e6f15e fix clippy warnings uncovered by msrv bump 2023-06-05 07:08:27 +01:00
David Hewitt 1bbd556718 run cargo check instead of clippy for MSRV in CI 2023-06-04 23:15:59 +01:00
David Hewitt 8850d5d384 support ordering magic methods for `#[pyclass]` 2023-06-04 13:58:18 +01:00
Kang Seonghoon c2d4e8ad1f Use a full path for `#[new]` method which is also `#[classmethod]`. 2023-05-29 11:01:48 +09:00
Kang Seonghoon d930bc14d9 Verify that various macros do work without any PyO3 imports. 2023-05-29 11:01:48 +09:00
bors[bot] 0e50338675
Merge #3171
3171: RFC: Simplify version handling of UI tests. r=davidhewitt a=adamreichold

 Due to checking in error outputs these tests only work reliably on stable and not on intermediate version between our MSRV (currently 1.48) and the current stable version.

Hence this simplifies things to run only MSRV-compatible tests for the MSRV builds, anything else for stable builds except for those tests which require the nightly feature, i.e. the `Ungil` being distinct from the `Send` trait.

Finally, `not_send3` is disabled when using the nightly feature since while `Rc` is not send, it also not GIL-bound and hence can be passed into `allow_threads` as it does not actually spawn a new thread.


Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-25 20:20:49 +00:00
Adam Reichold 90fcc63eda Replace the nightly UI tests by doctests since we cannot keep up with the changing error outputs of nightly in any case. 2023-05-25 21:37:32 +02:00
Adam Reichold 8b14797403 Also ignore error outputs on MSRV to further simplify UI tests. 2023-05-25 21:37:05 +02:00
Adam Reichold 426e18932b Simplify version handling of UI tests.
Due to checking in error outputs these tests only work reliably on stable and
not on intermediate version between our MSRV (currently 1.48) and the current
stable version.

Hence this simplifies things to run only MSRV-compatible tests for the MSRV
builds, anything else for stable builds except for those tests which require the
nightly feature, i.e. the `Ungil` being distinct from the `Send` trait.

Finally, `not_send3` is disabled when using the nightly feature since while `Rc`
is not send, it also not GIL-bound and hence can be passed into `allow_threads`
as it does not actually spawn a new thread.
2023-05-25 21:34:43 +02:00
Kang Seonghoon e884327675 Add additional tests for #3165. 2023-05-25 21:31:17 +02:00
Kang Seonghoon 7cb1ad049f Rename a misleading test name and add an actual panicking test. 2023-05-25 21:31:17 +02:00
bors[bot] 32c335e072
Merge #3168 #3176
3168: Do not apply deferred ref count updates and prevent the GIL from being acquired inside of __traverse__ implementations. r=davidhewitt a=adamreichold

Closes #2301
Closes #3165


3176: Prevent dropping unsendable classes on other threads. r=davidhewitt a=adamreichold

Continuing the discussed from https://github.com/PyO3/pyo3/pull/3169#issuecomment-1556571504 and https://github.com/PyO3/pyo3/pull/3169#issuecomment-1556661723:

We already have checks in place to avoid borrowing these classes on other threads but it was still possible to send them to another thread and drop them there (while holding the GIL).
    
This change avoids running the `Drop` implementation in such a case even though Python will still free the underlying memory. This might leak resources owned by the object, but it avoids undefined behaviour due to access the unsendable type from another thread.
    
This does assume that the object was not unsafely integrated into an intrusive data structures which still point to the now freed memory. In that case, the only recourse would be to abort the process as freeing the memory is unavoidable when the tp_dealloc slot is called. (And moving it elsewhere into a new allocation would still break any existing pointers.)

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-25 18:18:46 +00:00
Adam Reichold e85bfcc3bf Factor out UnraisableCapture helper type and use it to check that dropping unsendable elsewhere calls into sys.unraisablehook 2023-05-25 20:17:55 +02:00
Adam Reichold 08bdc32b6e Move traverse-bare-self UI test to version-gated section as its error output is not stable between MSRV and current stable. 2023-05-25 20:02:51 +02:00
Adam Reichold 18397828e5 Move locking the GIL and handling the resulting panics into a library function. 2023-05-25 20:01:35 +02:00
Adam Reichold 810ad00a76 Do not apply deferred ref count updates and prevent the GIL from being acquired inside of implementations. 2023-05-25 20:01:35 +02:00
Adam Reichold 501ff8a17d Prevent dropping unsendable classes on other threads.
We already have checks in place to avoid borrowing these classes on other
threads but it was still possible to send them to another thread and drop them
there (while holding the GIL).

This change avoids running the `Drop` implementation in such a case even though
Python will still free the underlying memory. This might leak resources owned by
the object, but it avoids undefined behaviour due to access the unsendable type
from another thread.

This does assume that the object was not unsafely integrated into an intrusive
data structures which still point to the now freed memory. In that case, the
only recourse would be to abort the process as freeing the memory is unavoidable
when the tp_dealloc slot is called. (And moving it elsewhere into a new
allocation would still break any existing pointers.)
2023-05-25 19:10:42 +02:00
Adam Reichold 62f424b690 Drop EnsureGIL to remove one layer of indirection from the implementation of Python::with_gil 2023-05-23 23:31:47 +02:00
Kang Seonghoon 24343f2caa Fix a span site of `_slf` for custom receivers. 2023-05-23 10:25:57 +09:00
David Hewitt 248230b8e4 refactor PyAny::is_instance_of for performance 2023-05-18 22:25:27 +01:00
Adam Reichold b9766cfa11 Add PyClass::get and Py::get for GIL-independent access to frozen classes. 2023-05-18 08:57:55 +02:00
Stu Hood 20c5618160
Add support for combining the `#[new]` and `#[classmethod]` method types. 2023-05-16 15:51:14 -07:00