Commit Graph

88 Commits

Author SHA1 Message Date
Aneesh Agrawal c67625d683
Revamp PyType name functions to match PEP 737 (#4196)
* Revamp PyType name functions to match PEP 737

PyType::name uses `tp_name`, which is not consistent.
[PEP 737](https://peps.python.org/pep-0737/) adds a new path forward,
so update PyType::name and add PyType::{module,fully_qualified_name}
to match the PEP.

* refactor conditional code to handle multiple Python versions better

* return `Bound<'py, str>`

* fixup

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-06-22 22:10:27 +00:00
David Hewitt 0b967d427a
use `ffi::MemberGef` for `#[pyo3(get)]` fields of `Py<T>` (#4254)
* use `ffi::MemberGef` for `#[pyo3(get)]` fields of `Py<T>`

* tidy up implementation

* make it work on MSRV :(

* fix docs and newsfragment

* clippy

* internal docs and coverage

* review: mejrs
2024-06-21 23:33:34 +00:00
Adam Reichold c5f9001985
Remove deferred reference count increments and make the global reference pool optional (#4095)
* Add feature controlling the global reference pool to enable avoiding its overhead.

* Document reference-pool feature in the performance guide.

* Invert semantics of feature to disable reference pool so the new behaviour becomes opt-in

* Remove delayed reference count increments as we cannot prevent reference count errors as long as these are available

* Adjust tests to be compatible with disable-reference-pool feature

* Adjust tests to be compatible with py-clone feature

* Adjust the GIL benchmark to the updated reference pool semantics.

* Further extend and clarify the documentation of the py-clone and disable-reference-pool features

* Replace disable-reference-pool feature by pyo3_disable_reference_pool conditional compilation flag

Such a flag is harder to use and thereby also harder to abuse. This seems
appropriate as this is purely a performance-oriented change which show only be
enabled by leaf crates and brings with it additional highly implicit sources of
process aborts.

* Add pyo3_leak_on_drop_without_reference_pool to turn aborts into leaks when the global reference pool is disabled and the GIL is not held
2024-05-11 14:48:45 +00:00
Icxolu aef0a05719
deprecate implicit default for trailing optional arguments (#4078)
* deprecate "trailing optional arguments" implicit default behaviour

* add newsfragment

* generate individual deprecation messages per function

* add migration guide entry
2024-05-10 10:34:58 +00:00
Icxolu 21c02484d0
feature gate APIs using `into_gil_ref` (Part 2) (#4166) 2024-05-09 22:21:48 +00:00
David Hewitt 351c6a0a49
deprecate optional GIL Ref in function argument (#3975) 2024-03-21 07:24:40 +00:00
David Hewitt 870a4bb20d
deprecate GIL refs in function argument (#3847)
* deprecate GIL Refs in function arguments

* fix deprecated gil refs in function arguments

* add notes on deprecations limitations to migration guide

* Apply suggestions from code review

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

* review: Icxolu

* fix proto method extract failure for option

* fix gil refs in examples

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-03-20 22:35:08 +00:00
Icxolu b06e95727b
deprecate gil-refs in `from_py_with` (#3967)
* deprecate gil-refs in `from_py_with`

* review feedback davidhewitt
2024-03-19 08:58:41 +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
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
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 76dabd4e60
Replace as_ref(py) with Bound APIs (#3863) 2024-02-19 22:39:54 +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 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 e45fbe493c port `IntoPyDict` to `Bound` API 2024-02-10 15:47:26 +01:00
David Hewitt eed196329d add list bound constructors 2024-01-27 21:12:55 +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
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 7d486bb72a tests/common.rs -> src/tests/common.rs 2023-09-24 13:34:53 +01:00
David Hewitt 4f3fcdbf0f remove all functionality deprecated in PyO3 0.18 2023-06-13 22:27:43 +01:00
Kang Seonghoon 24343f2caa Fix a span site of `_slf` for custom receivers. 2023-05-23 10:25:57 +09: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
David Hewitt 33871b7aea allow **kwargs to take arguments which conflict with positional-only parameters 2022-12-17 07:22:28 +00:00
David Hewitt 8e8b484169
add `#[pyo3(signature = (...))]` attribute (#2702) 2022-10-25 07:23:21 +01:00
David Hewitt c445eba28d pyfunction: fix compile error for Option<&T> argument with a default 2022-09-20 15:44:55 +02:00
mejrs 984fdf57c7 Use Python:;with_gil in tests 2022-07-19 19:34:23 +02: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
cuishuang 19e32a0621 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-04-24 22:06:32 +08:00
mejrs 6f1cf1b662 Add more lints 2022-03-23 08:07:28 +01:00
David Hewitt ddf13ea98f clippy: enable some more lints 2022-03-03 07:23:28 +00:00
David Hewitt 6433d884fc dev: remove self dev dependency 2021-12-08 07:48:58 +00:00
David Hewitt 4b2345fe80 pymethods: support __call__ proto 2021-10-23 00:06:46 +01:00
Ashley Anderson bf26daec2d
Positional-only args (#1925)
* Add support for positional-only args

* Update changelog. Add a few more tests. Run rust-fmt.

* Fix test.

* Fix tests again.

* Update CHANGELOG.md to link PR instead of issue

* Update guide to mention positional-only params

* Add unreachable!() per code review

* Update and expand tests for pos args.

* Fix tests, lint, add UI tests.

Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
2021-10-19 23:13:27 +01:00
scalexm 7e8eeec02f Add a test 2021-06-25 00:18:53 +02:00
David Hewitt ce851ad7d9 1506: fixes to macro hygiene 2021-03-28 11:01:51 +01:00
David Hewitt e34e87ad4a 1505: add CHANGELOG and test 2021-03-20 08:36:19 +00:00
kngwyu 9b88a452e2 Refactor tests to use shorter macros 2021-03-14 23:43:53 +09:00
David Hewitt 29a525b327 pyfunction: refactor argument extraction 2021-03-01 17:49:46 +00:00
David Hewitt ffd5874c3a pyfunction: fix args conflicting with keyword only arg 2021-03-01 17:49:46 +00:00
David Hewitt b2675b11fe rust 1.50: clippy and lint fixes 2021-02-11 22:03:34 +00:00
David Hewitt 9807ef8ed4 macros-backend: fix raw idents in pymethods 2021-01-12 22:01:11 +00:00
Alex Gaynor 140790b15f Merge branch 'master' into abi3-merge-master 2020-10-10 10:11:49 -04:00
dvermd df984ec8df
Keyword only arguments (#1209)
* allow keyword arguments without default value

* allow keyword-only arguments
2020-10-01 13:34:54 +09:00
Alex Gaynor 117f60bed0 Make PyType::name abi3 compatible
The implementation is more complex, because there's no equivalent to tp_name in the limited API
2020-09-08 12:22:59 -04:00
kngwyu f5f2e84f4b Enable &Self in #[pymethods] again 2020-07-28 20:55:38 +09:00
David Hewitt 4ed9748b45 Rename exceptions to PyException etc; reintroduce deprecated ones 2020-07-18 06:02:57 +01:00
kngwyu 1e39071c04 Retrieve FromPyObject implementation for &PySequence 2020-03-22 20:00:21 +09:00
kngwyu cea707dd1c Inhibit positional args after * 2020-03-06 14:01:27 +09:00