Commit Graph

1013 Commits

Author SHA1 Message Date
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
bors[bot] 7b443cf813
Merge #2981
2981: Remove 0.17 deprecations r=adamreichold,davidhewitt a=davidhewitt

Since #2980 starts a breaking change for 0.19, let's also clean up all 0.17's deprecations.

I've removed `Python::acquire_gil` in its own commit, as that was a reasonably chunky removal.

Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-05-09 08:08:06 +00:00
David Hewitt dd24c9ea71 remove `Python::acquire_gil` 2023-05-09 09:39:23 +02:00
Adam Reichold 0773651407 Add test case requiring the maximum lifetime of the holder references. 2023-05-06 12:42:05 +02:00
bors[bot] 1cdac4fde4
Merge #2980
2980: support `text_signature` on `#[new]` r=adamreichold a=davidhewitt

Closes #2866 

This is a breaking change for 0.19.0, because it starts autogenerating `text_signature` for `#[new]`. This could affect runtime behaviour if the user is relying on the class docs at runtime for some reason.

Guide & tests all updated accordingly.

`#[pyclass(text_signature = "...")]` is deprecated by this PR, however if it's set, it will be used in preference to `#[new]`.

(The signature / `text_signature` from `#[new]` will simply be ignored in this case. I figure that when users fix their deprecation warnings by removing `#[pyclass(text_signature = "...")]` then the `#[new]` signatures will start flowing properly, and this is good enough.)

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
2023-05-04 16:51:54 +00:00
Adam Reichold bd4b550495 Do not assert class text signature using the limited API before version 3.10 as we do not support it. 2023-05-04 18:28:43 +02:00
David Hewitt 8bd17f02c7 support `text_signature` on `#[new]` 2023-05-04 07:15:11 +01:00
BlueGlassBlock f75ea3d93a
test: improve cov 2023-04-27 12:44:38 +08:00
BlueGlassBlock 28cc9e3f6c
chore: EOF ui test 2023-04-26 20:08:46 +08:00
BlueGlassBlock 158410fc77
fix: ui test stderr 2023-04-26 20:05:43 +08:00
BlueGlassBlock 1d6ab21781
fix: change to from_item_all 2023-04-26 19:47:07 +08:00
BlueGlassBlock c415d79bf7
test(ui): TRYBUILD=overwrite 2023-04-26 13:02:22 +08:00
BlueGlassBlock 5f4acd72d0
test: add ui tests 2023-04-26 12:48:12 +08:00
Adam Reichold 04d962e2ed Update UI tests for Rust 1.69.0. 2023-04-21 16:22:42 +02:00
messense 57dbc94293
Improve default value for `None` in `text_signature` 2023-03-29 10:14:44 +08:00
Solomon Ucko 7e2f732d7a fix typo DateType -> DateTimeType, fixes #3069 2023-03-28 18:45:39 +02:00
bors[bot] ebedcfb8b2
Merge #3050
3050: Improve default values for str, numbers and bool in `text_signature` r=davidhewitt a=messense

xref #2863

Co-authored-by: messense <messense@icloud.com>
2023-03-25 07:07:06 +00:00
bors[bot] e5e8c7a6d0
Merge #2975 #3022 #3023
2975: RFC: Add GILProtected synchronization primitive and use it for LazyTypeObjectInner. r=davidhewitt a=adamreichold

I would also like to use that type in rust-numpy and it seems we can avoid ~~both a manual unsafe impl and~~ a full blown mutex if we apply it to `LazyTypeObjectInner`.

One downside might be that it ties us closer to the GIL when we want to enable nogil experimentation, but on the other hand, it may also help by reifying the GIL usage. (This is currently limited to comments in unsafe code in rust-numpy for example.)

3022: Fix function name shadowing r=davidhewitt a=mejrs

Fixes https://github.com/PyO3/pyo3/issues/3017

3023: Emit a better error for bad argument names r=davidhewitt a=mejrs

This will emit a better error for code like 
```rust
#[pyfunction]
fn output([a,b,c]: [u8;3]) {}
```



Co-authored-by: Adam Reichold <adam.reichold@t-online.de>
Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2023-03-23 08:04:11 +00:00
mejrs 1ecc71638d Emit a better error for bad argument names 2023-03-23 07:43:54 +00:00
Will Stott b05795307c Test static __getitem__ as well as __len__ 2023-03-18 13:56:51 +00:00
Will Stott bcdb17db5b Fix compile error when trying to use static slot methods 2023-03-18 11:16:52 +00:00
messense 79a70f3923
Improve default values for str, numbers and bool in `text_signature` 2023-03-16 11:06:51 +08:00
bors[bot] dd6498142f
Merge #3014
3014: feat: add #[pyo3(get, set)] for Cell r=davidhewitt a=AntoineRR

This fixes #2659.
The types for which `#[pyo3(get, set)]` should now work are `Cell`, `Arc` and `Box`.

There is one issue regarding `Box`, the implementation of `FromPyObject` conflicts with another one. I could not find what the issue was, especially since the other implementations for `Arc` and `Cell` work as expected. The related code and test has been commented out for now. Maybe someone could help me fix this issue if I don't figure it out myself? There is also the possibility to remove the implementation for `Box` of course.


Co-authored-by: Antoine Romero-Romero <ant.romero2@orange.fr>
2023-03-10 06:13:28 +00:00
David Hewitt cd36c6fc21 fix clippy and ui tests for Rust 1.68 2023-03-09 23:41:26 +00:00
Antoine Romero-Romero a629e8267a feat: add #[pyo3(get, set)] for Cell 2023-03-09 23:09:30 +00:00
David Hewitt 7a2b1f0e13 fix `non_snake_case` lint for `#[pyfunction]` generated code 2023-02-28 08:44:17 +00:00
David Hewitt 226bf97ec0 Fix `clippy::redundant_closure` lint firing for pyfunction defaults 2023-02-27 22:10:06 +00:00
Adam Reichold 577570e8c4 Reduce visibility of CaptureStdErr type to avoid warnings on older toolchains. 2023-02-18 17:11:40 +01:00
David Hewitt c7cc48f8e4 use PyO3 types within LazyTypeObject 2023-02-18 09:06:36 +00:00
David Hewitt 00ddd21535 change PyModule::add_class to return an error if class creation fails 2023-02-14 22:08:35 +00:00
bors[bot] 864aee0916
Merge #2930
2930: add better error message for Python in signature r=adamreichold a=davidhewitt

Inspired by #2929, this just adds a better error message when `Python` arguments are accidentally included in the signature.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-02-03 09:11:26 +00:00
David Hewitt 96efb0eda9 add better error message for Python in signature 2023-02-03 06:57:30 +00:00
Armin Ronacher 066880e7d5 Added support for PyErr_WriteUnraisable 2023-01-29 20:01:22 +00:00
Nate Kent f11290d314
Add additional unit test for GC traversal
Since we're just testing a bug during traversal, we don't actually have
to reap the object, we just have to make a reference cycle so that it's
traverse method is called.
2023-01-26 16:27:54 -08:00
mejrs 2052269aea Update rust 1.67 2023-01-26 21:44:05 +01:00
David Hewitt 586fed2c4b send errors in `__releasebuffer__` to `sys.unraisablehook` 2023-01-19 19:10:06 +00:00
David Hewitt 8f48d157d6 deprecate required arguments after option arguments without signature 2023-01-15 10:17:20 +00:00
bors[bot] 8af48bbb53
Merge #2796
2796: Forward cfgs on pyclass fields to the method defs r=davidhewitt a=mejrs

With this and the cfg_attr PR, I don't need cfg_eval at all anymore :)


- [x] needs some more tests

Co-authored-by: mejrs <>
2022-12-29 16:28:26 +00:00
mejrs 5198722dd9 Add test 2022-12-28 23:11:39 +01:00
Alex Gaynor 4875e4b6bf update URL in comment to point at correct place
The branch has drifted and those line ranges are no longer accurate.
2022-12-28 20:48:11 +01:00
David Hewitt f2608a923c remove functionality deprecated in 0.16 2022-12-28 12:23:53 +00:00
David Hewitt 5039fd746a add automatic text signature generation 2022-12-24 09:43:02 +00:00
David Hewitt 33871b7aea allow **kwargs to take arguments which conflict with positional-only parameters 2022-12-17 07:22:28 +00:00
David Hewitt f01b245d85 update ui tests for Rust 1.66 2022-12-16 20:56:15 +00:00
bors[bot] 08423557d4
Merge #2739
2739: error when `#[pyo3(signature = ())]` used on invalid methods r=davidhewitt a=davidhewitt

A follow-up to #2702 to reject some invalid applications of `#[pyo3(signature = (...))]` attribute, specifically on magic methods and getters / setters / class attributes.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-11-22 19:41:27 +00:00
Georg Brandl 99c8dea30e Use Python::get_type() instead of PyTypeInfo::type_object()
The former needs one less import and uses a familiar object.
2022-11-20 15:16:18 +01:00
Georg Brandl 2a630a2a52 Fix being able to call arg-less `#[new]` with any args from Python
Fixes #2748
2022-11-20 08:25:19 +01:00
Georg Brandl c489809938 Py/PyAny: deprecate cast_as() in favor of downcast()
They are (practically) identical on PyAny, and `downcast()` is the more
useful name.
2022-11-18 07:00:40 +01:00
David Hewitt 00fc0358b9 error when `#[pyo3(signature = ())]` used on invalid methods 2022-11-17 08:28:34 +00:00
Bruno Kolenbrander 6766d9f93b
Merge pull request #2686 from dalcde/closure-name-doc
Support passing name and doc to new_closure.
2022-11-06 17:35:20 +01:00
messense 0e770a8458 Update ui tests for Rust 1.65.0 2022-11-04 06:35:30 +00:00
Dexter Chua 9201a7dd48 Support passing name and doc to PyCFunction::new_closure. Fixes #2665 2022-10-29 12:26:09 +08:00
David Hewitt 8e8b484169
add `#[pyo3(signature = (...))]` attribute (#2702) 2022-10-25 07:23:21 +01:00
David Hewitt 747d791f1f
introduce trampolines for methods (#2705) 2022-10-25 07:22:36 +01:00
David Hewitt 446c0e82f0
Merge pull request #2692 from mejrs/all
Implement get/set all on pyclass
2022-10-18 21:39:44 +01:00
mejrs 08c8b845aa Create better error spans/messages 2022-10-18 21:14:22 +02:00
mejrs d254134154 Implement get/set all on pyclass 2022-10-17 02:37:43 +02:00
Bruno Kolenbrander 4a04603c2c
Don't use intocallback in method macros (#2664)
* Don't use intocallback in method macros

Co-authored-by: mejrs <>
2022-10-16 10:35:58 +01:00
David Hewitt 8102ad1a1b rust: updates for 1.64 2022-09-22 21:03:34 +02:00
David Hewitt c5ba1f0632
pyclass: better error and explanation why lifetimes are disallowed (#2633)
* pyclass: better error and explanation why lifetimes are disallowed

* extend detail on lifetimes
2022-09-22 11:14:06 +02:00
David Hewitt c445eba28d pyfunction: fix compile error for Option<&T> argument with a default 2022-09-20 15:44:55 +02:00
Jonathan Coates 26a9603519 Some improvements to __richcmp__ on enums
- Implement __ne__ as well as __eq__.
 - Return NotImplemented when types cannot be converted, rather than
   throwing.
 - Compare the integer ids inside the __eq__/__ne__ implementation.
   Previously a match block was generated.
2022-09-16 15:30:56 +01:00
Ivan “CLOVIS” Canet d7c1a2906a
IntoPy and FromPyObject allow the retrieval of the type information 2022-09-06 21:30:36 +02:00
David Hewitt 5718adeec7 pyproto: remove deprecated feature 2022-09-06 08:38:44 +01:00
David Hewitt 9d543b3f4b pyfunction: fix from_py_with on Option<T> argument 2022-08-25 18:57:17 +01:00
David Hewitt 36ecadd69f ci: unpin serde, fixup nightly ui tests 2022-08-23 08:07:26 +01:00
David Hewitt d0492b7c72
Merge pull request #2570 from davidhewitt/pyclass-frozen-tidy
pyclass: tidy up frozen implementation
2022-08-21 09:35:51 +01:00
David Hewitt 24456f3f41 pyclass: tidy up frozen implementation 2022-08-21 08:21:06 +01:00
David Hewitt fd8026c7bb pyclass: add `sequence` option to implement `sq_length` 2022-08-20 07:14:26 +01:00
mejrs fc6121eafe Deprecate acquire_gil 2022-08-15 03:34:47 +02:00
David Hewitt c58ff7758c pypy: disable PyFunction 2022-08-13 17:51:10 +01:00
David Hewitt 987858f5fa ci: ui tests for 1.63 2022-08-12 07:26:29 +01:00
messense db177a07ad
Fix new clippy warnings in Rust 1.63.0 2022-08-12 11:50:23 +08:00
Ashley Anderson 5d88e1d1c4
Update PyTryFrom for PyMapping and PySequence to more accurately check types (#2477)
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-08-10 21:03:18 +01:00
David Hewitt 78ba70d2b4 pymodule: only allow initializing once per process 2022-08-09 19:52:25 +01:00
mejrs 984fdf57c7 Use Python:;with_gil in tests 2022-07-19 19:34:23 +02:00
David Hewitt d5e99b635d refactor: remove all 0.15 deprecations 2022-07-15 06:33:14 +01:00
David Hewitt 7babd13830 datetime: support timezone bindings 2022-07-13 22:05:17 +01:00
David Hewitt 97ce1f6892 ci: fix nightly UI tests 2022-07-13 08:06:14 +01:00
Ivan Krivosheev 1cd1dbfe8b
Add super object (#2486) 2022-07-03 19:21:15 +01:00
Bruno Kolenbrander 58d4ba833e
Rust 1.62 (#2489)
* Rust 1.62

* Make rust happy

* Just use a doctest instead

Co-authored-by: mejrs <>
2022-07-02 16:08:01 +01:00
David Hewitt 4da9c3a55f llvm-lines: use iterator to collect class items 2022-06-25 22:03:28 +01:00
David Hewitt 62f27caffe ci: fix nightly ui tests 2022-06-25 21:12:14 +01:00
Ashley Anderson bde5102eb8
Increasing test coverage (#2462)
* cov: src/buffer.rs - add tests for debug and element from format

* cov: src/buffer.rs - add some fortran-specific calls in test_array_buffer

* fix issues in MSRV

* cov: src/types/function.rs - directly call PyCFunction::new and PyCFunction::new_with_keywords

* docs: clarify docs of PyCFunction::new and PyCFunction::new_with_keywords

* revert added rust-version for MSRV in Cargo.toml

* cov: src/types/slice.rs - simple tests for PySliceIndices::new

* fix for multi-platform

* Update src/types/function.rs

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>

* cov: src/buffer.rs - a better PyBuffer Debug test

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2022-06-23 21:30:22 +01:00
Gabriel Smith 75656949f9 macros: Support #[pyo3(name)] on enum variants 2022-06-22 09:36:40 -04:00
Gabriel Smith 2122faa547 macros: Use macro-defined name for enums in __repr__ 2022-06-21 16:31:23 -04:00
David Hewitt 7725f17c46 pyclass: switch from immutable to frozen 2022-06-19 21:18:15 +01:00
David Hewitt 517f4a87a9
Merge pull request #2450 from mejrs/misc
Fix UB in *_offset functions
2022-06-18 08:53:10 +01:00
David Hewitt f81a01b604 macros: emit pymethod associated methods as a single block 2022-06-16 22:15:29 +01:00
Ivan Krivosheev f19561c745 Allow #[classattr] take Python argument 2022-06-16 13:08:53 +03:00
mejrs 2d3a5852ed Avoid UB in *_offset methods 2022-06-12 15:11:39 +02:00
David Hewitt 7c56a03d64 frompyobject: fix `from_py_with` ignored for transparent structs 2022-06-09 06:49:25 +01:00
Hood Chatham da5b9814cc
Set up CI for wasm32-emscripten target (#2436)
* ci: test on emscripten target

This adds CI to build libpython3.11 for wasm32-emscripten and
running tests against it. We need to patch instant to work
around the emscripten_get_now:
https://github.com/sebcrozet/instant/pull/47

We also have to patch emscripten to work aroung the "undefined
symbol gxx_personality_v0" error:
https://github.com/emscripten-core/emscripten/issues/17128

I set up a nox file to download and install emscripten,
download and build cpython, set appropriate environment variables
then run cargo test. The workflow just installs python, rust,
node, and nox and runs the nox session.

I xfailed all the test failures. There are problems with datetime.
iter_dict_nosegv and test_filenotfounderror should probably be
fixable. The tests that involve threads or asyncio probably can't
be fixed.

* Some cleanup

* Remove instant patch

* Add explanations for xfails
2022-06-08 05:59:18 +01:00
David Hewitt cdf86482d8 ffi: many fixes to pypy definitions 2022-06-04 12:47:40 +01:00
David Hewitt a746411b24
Merge pull request #2422 from davidhewitt/frompyobject-fixes
frompyobject: improve error messages of derived impls
2022-06-02 13:30:03 +01:00
David Hewitt f50406a034
Merge pull request #2413 from davidhewitt/simpler-interned
macros: simpler expansion for `intern!`
2022-06-02 12:54:11 +01:00
David Hewitt 0aa4f95a98 frompyobject: improve error messages of derived impls 2022-06-02 11:13:35 +01:00
David Hewitt 261c0c5f56 macros: simpler expansion for `intern!` 2022-06-02 09:57:58 +01:00
David Hewitt cfb91057af frompyobject: improve error message for tuple case 2022-06-02 08:54:20 +01:00
David Hewitt eafbbc5417
Merge pull request #2399 from davidhewitt/avoid-duplicate-pymethods
pymethods: prevent methods sharing the same name
2022-05-24 22:22:31 +01:00
David Hewitt 879eb14e27
Merge pull request #2395 from davidhewitt/fix-class-raw-ident
macros: fix raw-ident pyclasses having r# at the start of the Python name
2022-05-24 22:08:56 +01:00
David Hewitt 71abeeff8b macros: fix raw-ident pyclasses having r# at the start of the Python name 2022-05-24 21:34:23 +01:00
David Hewitt a306365db8 pymethods: prevent methods sharing the same name 2022-05-24 21:15:30 +01:00
David Hewitt 126bf49b8b
Merge pull request #2377 from herquan/herquan_cr1
Add macro append_to_inittab (issue #2359)
2022-05-24 08:02:47 +01:00
herquan 2ec477344d Add macro append_to_inittab
Sometimes we need to debug in a real environment with our module installed. `append_to_inittab` will be a wrapper for PyImport_AppendInittab (https://docs.python.org/3/c-api/import.html#c.PyImport_AppendInittab) and help us to do this
2022-05-24 07:42:15 +01:00
David Hewitt 0de0e3f8d6 Allow `#[classattr]` methods to be fallible 2022-05-17 21:19:41 +01:00
David Hewitt 8636db67f5 add regression test for PEP 587 2022-05-15 16:08:21 +01:00
Bruno Kolenbrander c57e5098b8
Fix IntoPyCallbackOutput paper cuts (#2326)
* Implement IntoPy for arrays of IntoPy

* Improve `IntoPyCallbackOutput` compile error
2022-05-09 18:15:43 +01:00
Bruno Kolenbrander dce4377eb4
Allow more methods to take interned arguments (#2312)
* Allow more methods to take interned arguments

* Changelog

* Unify name bounds

* Resolve merge conflict

* reduce use of py_decref

* Add some attr tests

* Update migration
2022-05-02 11:13:15 +02:00
David Hewitt 4168feed1b opt: tidy some generic code bloat 2022-04-26 05:36:57 +01:00
cuishuang 19e32a0621 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-04-24 22:06:32 +08:00
David Hewitt 7e2d3117ce cleanup: deprecate PyTypeObject trait 2022-04-23 13:36:32 +01:00
David Hewitt e9bd41efb2 better mutability inheritance rules 2022-04-21 20:51:28 +01:00
mejrs 53a642eda7 Fix ui test 2022-04-12 15:49:23 +02:00
Bruno Kolenbrander bc6bd6099c
Merge branch 'main' into immutable 2022-04-12 14:22:33 +02:00
mejrs b7745dffc8 Fix everything 2022-04-12 14:19:02 +02:00
mejrs 4fc0cdd636 Fix ui test 2022-04-07 23:56:15 +02:00
David Hewitt c16cc35b30 pyclass: mapping flag 2022-04-02 16:15:44 +01:00
mejrs 086424b88c Merge branch 'main' of https://github.com/mejrs/pyo3 into immutable 2022-04-01 23:11:02 +02:00
mejrs 9ab1e6927a Merge branch 'immutable' of https://github.com/mejrs/pyo3 into immutable 2022-04-01 22:59:59 +02:00
Bruno Kolenbrander 43944aef76
Create a better error message for moving self (#2238) 2022-03-24 10:27:37 +01:00
Bruno Kolenbrander fb689340b4
Merge branch 'main' into lint-more 2022-03-23 09:34:31 +01:00
mejrs 6f1cf1b662 Add more lints 2022-03-23 08:07:28 +01:00
David Hewitt 87c79c0319
Merge pull request #2234 from davidhewitt/pyclass-args-refactor
pyclass: unify pyclass with its pyo3 arguments
2022-03-22 11:38:05 +00:00
David Hewitt 5cc3ce99f1 pyclass: unify pyclass with its pyo3 arguments 2022-03-20 08:24:09 +00:00
Alex Gaynor 69655454c1 Added an as_bytes method for Py<PyBytes>
This allows for obtaining a slice that's not lexically bound to the GIL which can be helpful to avoid copying.
2022-03-19 13:28:06 -04:00
David Hewitt ddf13ea98f clippy: enable some more lints 2022-03-03 07:23:28 +00:00
David Hewitt b59ee9b54b misc: tidy ups pre 0.16 2022-02-27 10:02:28 +00:00
Georg Brandl 0678f11266 Protocols: implement __getattribute__
converting tp_getattro to a shared slot

Fixes #2186
2022-02-26 20:05:50 +01:00
Georg Brandl 03dc96bff1
Py/PyAny: remove PartialEq impl and add is() (#2183) 2022-02-25 19:39:45 +00:00
David Hewitt 7c865fcc25
Merge pull request #2173 from davidhewitt/deprecate-pyproto
pyproto: deprecate protocol traits
2022-02-24 23:54:40 +00:00
David Hewitt 424644181b pymethods: add support for inplace concat & repeat 2022-02-24 23:07:24 +00:00
Rico Hageman ed698c4b43 Add documentation related to from_py_with for the FromPyObject trait 2022-02-24 22:54:30 +01:00
Rico Hageman fc186cdb3b Remove item annotation in tuple struct 2022-02-24 22:20:54 +01:00
Rico Hageman 76233e1924 Address pull request comments 2022-02-24 11:27:53 +01:00
Rico Hageman 84a763da14 Add test to ensure support for from_py_with for enums 2022-02-24 00:22:33 +01:00
Rico Hageman 10804b0d65 Support from_py_with on struct tuples 2022-02-24 00:06:33 +01:00
David Hewitt 24445df633 pyproto: deprecate protocol traits 2022-02-23 07:50:52 +00:00
David Hewitt d8ee35e19c
Merge pull request #2165 from mejrs/auto_trait
Implement Auto trait
2022-02-23 07:16:17 +00:00
mejrs ec275d49cb Explicitly (un)implement Ungil 2022-02-22 22:43:40 +01:00
mejrs 10c3e5b094 Try to add nightly feature to CI
Fix stray "
2022-02-22 22:43:40 +01:00
mejrs 9e29c1058c Gut specialization and implement auto trait
Implement auto trait

Implement auto trait

Undo oopsie

Fix versions

Fix CI errors

Fix CI

Remove more specialization remnants
2022-02-22 22:43:23 +01:00
Rico Hageman 3fbdc863cb Include the causes when throwing a PyTypeError when argument parsing failed 2022-02-22 09:48:41 +01:00
Rico Hageman 597e3e17a9 Pass detailed error message to python when parsing an argument fails 2022-02-21 23:22:40 +01:00
David Hewitt 6af47c78f1 pymethods: more tests for magic methods 2022-02-16 07:42:25 +00:00
David Hewitt 79123b396c pyclass: deprecate gc option 2022-02-15 08:01:46 +00:00
David Hewitt 676295b8de pymethods: support gc protocol 2022-02-15 08:01:23 +00:00
David Hewitt c93ee00130 refactor: inline handle_panic into macro output 2022-02-10 20:20:03 +00:00
David Hewitt f5b2a88a70 refactor: include __new__ as slot 2022-02-09 08:07:14 +00:00
David Hewitt 6f39deaa37 finish off implementation 2022-02-08 18:17:44 +00:00
mejrs 7520b49ac1 Implement opt-in immutable pyclasses 2022-02-08 18:08:18 +00:00
b05902132 78f5afc82e Finish implementation for pyclass enums 2022-02-07 22:17:11 +00:00
David Hewitt f75579a489 python-3.11: support buffer API on abi3 2022-02-06 22:46:45 +00:00
David Hewitt ecfd2c2434 pyclass: simplify generated code for PyClassImpl 2022-02-05 16:58:01 +00:00
David Hewitt 558549e1c2 pyproto: split into new feature 2022-02-05 16:51:31 +00:00
David Hewitt 53c170078d pymethods: seq methods from mapping methods 2022-02-05 15:59:22 +00:00
David Hewitt abd7eafafb
Merge pull request #2134 from davidhewitt/optimize-extract-argument
opt: improve generated code for argument extraction
2022-02-05 00:33:45 +00:00
David Hewitt 1beb2bbb2d opt: optimize argument extraction 2022-02-04 20:53:49 +00:00
DSPOM 6a9a9ba38a
move ffi module to separate crate 2022-01-31 13:27:16 +01:00
mejrs 46c458181d Fix more formatting 2022-01-13 23:13:47 +01:00
mejrs f7d7da9b7a Try fix the ci some more 2022-01-13 23:11:33 +01:00
mejrs de175119c1 Formatting 2022-01-13 22:48:36 +01:00
mejrs a8a10ac33d gate the changed errors 2022-01-13 22:43:51 +01:00
mejrs 2006ee0d21 Fix ci 2022-01-13 22:25:23 +01:00
David Hewitt dc8032a5ff pyfunction: allow required positional after option 2022-01-11 00:44:41 +00:00
David Hewitt de8174684f pyfunction: allow wrap_pyfunction to work on imports (even cross-crate) 2022-01-07 08:43:05 +00:00
David Hewitt 2cee7feaaf
Merge pull request #2083 from aviramha/magic_methods
verify py method args count
2022-01-07 00:13:05 +00:00
Aviram Hassan 9ae31f2b87
fix tests 2022-01-06 09:59:10 +02:00
David Hewitt a9b98b7433 pymethods: __ipow__ always receive None on Python 3.7 2022-01-04 22:59:08 +00:00
David Hewitt be70e5441b
Merge pull request #2085 from davidhewitt/opt-argument-extraction
opt: move fastcall boilerplate out of generated code
2022-01-03 08:13:31 +00:00
Aviram Hassan 50659b6b02
`__ipow__` now supports modulo argument on Python 3.8+.
`pyo3-macros-backend` is now compiled with PyO3 cfgs to enable different magic method definitions based on version.
Add check for correct number of arguments on magic methods.
2022-01-03 09:53:56 +02:00
David Hewitt 1a782ce4db opt: move fastcall boilerplate out of generated code 2022-01-03 00:07:32 +00:00
David Hewitt cf965155f4 pymethods: support buffer protocol 2021-12-30 15:48:55 +00:00
David Hewitt e33b3e6a5b opt: don't emit T::dict_offset and T::weakref_offset without attributes 2021-12-30 14:57:27 +00:00
David Hewitt 807e126178 pyclass: no need to try inherit base dict and weaklist 2021-12-30 14:17:58 +00:00
David Hewitt ff37f24625 macros: accept paths in wrap_x macros 2021-12-30 12:46:57 +00:00
David Hewitt 5be5d77589 opt: improve handle_panic generated code 2021-12-24 00:17:04 +00:00
David Hewitt 492b7e4c0f macros: optimize generated code for #[derive(FromPyObject)] 2021-12-22 08:34:05 +00:00
David Hewitt 5cab5d4da3 misc: remove some more *const -> *mut pointer casts 2021-12-20 20:36:46 +00:00
David Hewitt 469d72a001
Merge pull request #2022 from PyO3/pyo3_path
Hygiene: offer a way to set path to pyo3 crate
2021-12-09 20:27:48 +00:00
Juniper Parsons 47cf13239f
Disallow positional args after optional args 2021-12-09 10:01:59 -05:00
Georg Brandl a5b76bc365 pyo3_path, part 4: rename to `crate` to keep consistent with serde 2021-12-09 07:36:48 +01:00
Georg Brandl 681217d8d9 pyo3_path, part 3: move test_hygiene into lib crate
This removes the crate-root `pyo3` item to ensure that our
selected pyo3_path needs to be taken into account.
2021-12-09 07:36:48 +01:00