Commit Graph

372 Commits

Author SHA1 Message Date
David Hewitt 5798caf1f8 better `Some`-wrapping for default arguments 2023-09-21 21:14:44 +01:00
David Hewitt e28403e772 call PyObject_GC_Untrack before deallocating 2023-09-09 22:29:58 +01:00
David Hewitt 4c46d81afd simplify thread checker implementation 2023-09-03 14:15:26 +01:00
David Hewitt f7503afbc8 remove all #py quoting 2023-08-18 14:04:38 +01:00
Adam Reichold 9363491d54
Merge pull request #3384 from DataTriny/pyclass_rename_variants
Add  `rename_all` attribute to `#[pyclass]`
2023-08-16 19:06:37 +00:00
David Hewitt eba2c59778 tidy up some file locations after dual licensing 2023-08-16 08:22:51 +01:00
DataTriny 3c3e9401a3 Dual-license 2023-08-15 23:39:45 +02:00
DataTriny 1a73ce6e60 Address review comments 2023-08-15 20:56:13 +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 a9e9ec628d
Add attribute to 2023-08-13 18:25:07 +02:00
David Hewitt 64adab1a76 add as_ptr and into_ptr inherent methods 2023-08-11 10:49:42 +01:00
David Hewitt 284c42d840 release: 0.19.2 2023-08-01 07:29:04 +01:00
David Hewitt 686fe0aac2 add macro quotes module for common snippets 2023-07-29 21:24:11 +01:00
David Hewitt e86dbab387 macros: `_py` -> `py` 2023-07-29 21:24:11 +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 45ff25cd2a clippy: deny / fix used-underscope-binding lint 2023-07-16 20:49:45 +01:00
David Hewitt 52cd9cbc90 macros: change self_arg to be an expression 2023-07-14 13:18:57 +01:00
David Hewitt b65cbb958b ci: updates for rust 1.71 2023-07-14 12:10:37 +01:00
David Hewitt bb05896324
Merge pull request #3311 from davidhewitt/frozen-receiver-error
improve error span for mutable access to `#[pyclass(frozen)]`
2023-07-12 06:21:25 +00:00
David Hewitt 56b7c38e24 improve error span for mutable access to `#[pyclass(frozen)]` 2023-07-11 22:34:53 +01:00
David Hewitt a5d97b3ad0 remove some dead fields from FnArg 2023-07-11 19:59:12 +01:00
Adam Reichold bd7aed4b12 Add implementation of Iterator::size_hint for PyIterator
When the Python iterator backing `PyIterator` has a `__length_hint__` special
method, we can use this as a lower bound for Rust's `Iterator::size_hint` to
e.g. support pre-allocation of collections.

This is implemented using `PyObject_LengthHint` which is not available in the
stable ABI and hence so is `Iterator::size_hint`. This should be fine since this
is an optimization in any case and the stable ABI is expected to have slightly
worse performance overall.
2023-07-09 10:16:20 +02:00
David Hewitt bf2f441567 prefer inner / _private naming 2023-07-04 21:03:24 +01:00
David Hewitt 7d357ad992 release: 0.19.1 2023-07-03 16:18:24 +01:00
mejrs 51a6863440 Give a better error message for Python in traverse 2023-06-19 23:25:51 +02:00
Alex Gaynor afbb1d435c
Upgrade to syn 2 2023-06-14 07:03:33 -04: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] 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
Adam Reichold 5738edfdd4 Bump MSRV to 1.56 2023-06-04 23:02:30 +01:00
David Hewitt 8850d5d384 support ordering magic methods for `#[pyclass]` 2023-06-04 13:58:18 +01:00
David Hewitt 45b5ede26a remove copyright headers from source files 2023-06-03 22:38:54 +01:00
David Hewitt 2500e22e13 release: 0.19.0 2023-05-31 13:53:37 +01:00
Kang Seonghoon c2d4e8ad1f Use a full path for `#[new]` method which is also `#[classmethod]`. 2023-05-29 11:01:48 +09: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
Kang Seonghoon 24343f2caa Fix a span site of `_slf` for custom receivers. 2023-05-23 10:25:57 +09:00
Stu Hood 20c5618160
Add support for combining the `#[new]` and `#[classmethod]` method types. 2023-05-16 15:51:14 -07:00
Adam Reichold 91cdfe4f7d Fix patch version of our dependency on syn. 2023-05-10 22:31:15 +02:00
bors[bot] c27a6333d6
Merge #3029
3029: use dynamic trampoline for all getters and setters r=adamreichold a=davidhewitt

This is an extension to the "trampoline" changes made in #2705 to re-use a single trampoline for all `#[getter]`s (and similar for all `#[setters]`). It works by setting the currently-unused `closure` member of the `ffi::PyGetSetDef` structure to point at a new `struct GetSetDefClosure` which contains function pointers to the `getter` / `setter` implementations.

A universal trampoline for all `getter`, for example, then works by reading the actual getter implementation out of the `GetSetDefClosure`.

Advantages of doing this:
- Very minimal simplification to the macro code / generated code size. It made a 4.4% reduction to `test_getter_setter` generated size, which is an exaggerated result as most code will probably have lots of bulk that isn't just the macro code.

Disadvantages:
- Additional level of complexity in the `getter` and `setter` trampolines and accompanying code.
- To keep the `GetSetDefClosure` objects alive, I've added them to the static `LazyTypeObject` inner.
- Very slight performance overhead at runtime (shouldn't be more than an additional pointer read). It's so slight I couldn't measure it.

Overall I'm happy to either merge or close this based on what reviewers think!

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2023-05-09 08:50:45 +00:00
David Hewitt 1ea57cb9ad use dynamic trampoline for all getters and setters 2023-05-09 08:09:59 +01:00
Adam Reichold a60945faa2 Do not store return values in locals so that holders benefit from lifetime extension for temporaries. 2023-05-06 16:26:18 +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
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 1d6ab21781
fix: change to from_item_all 2023-04-26 19:47:07 +08:00
BlueGlassBlock 30b2ed1d85
feat: add #[pyo3(item_all)] for FromPyObject 2023-04-25 19:37:05 +08:00
Adam Reichold 2c1762949e Fix some Clippy warnings only visible in the CI. 2023-04-14 18:41:45 +02:00
David Hewitt bfcc1f8c27 update release notes for 0.18.3 2023-04-13 22:47:55 +01:00
messense 57dbc94293
Improve default value for `None` in `text_signature` 2023-03-29 10:14:44 +08:00