David Hewitt
cf74624de9
refactor to remove add_to_module functions from generated code ( #4009 )
...
* refactor to remove add_to_module functions from generated code
* mrsv, newsfragment
* clippy
2024-03-29 11:54:33 +00:00
Icxolu
dd1710256d
use `extract_argument` for `#[setter]` extraction ( #3998 )
...
* use `extract_argument` for `#[setter]` extraction
* add newsfragment
2024-03-27 15:41:04 +00:00
Icxolu
35faeff6f1
handle `#[pyo3(from_py_with = "")]` in `#[setter]` methods ( #3995 )
...
* handle `#[pyo3(from_py_with = "")]` in `#[setter]` methods
* add newsfragment
2024-03-26 18:53:11 +00:00
David Hewitt
1be2fad9bf
release: 0.21.0 ( #3983 )
2024-03-25 23:36:08 +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
2736cf670c
deprecate gil-refs in `from_py_with` (Part 2) ( #3972 )
...
* deprecate `from_py_with` in `#[derive(FromPyObject)]` (NewType)
* deprecate `from_py_with` in `#[derive(FromPyObject)]` (Enum, Struct)
2024-03-20 09:27:38 +00:00
David Hewitt
02e188e4b4
adjust path for GIL Refs deprecation warnings ( #3968 )
2024-03-19 21:08:20 +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
Bruno Kolenbrander
989d2c53ab
Fix non_local_definitions lint triggers ( #3955 )
2024-03-12 22:59:33 +00:00
David Hewitt
67b1b35013
release: 0.21.0-beta.0 ( #3944 )
2024-03-10 22:16:18 +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
31c4820010
deprecate `&PyModule` as `#[pymodule]` argument type ( #3936 )
...
* deprecate `&PyModule` as `#[pymodule]` argument type
* cleanup
* add ui tests
* fix deprecations in tests
* fix maturin and setuptools-rust starters
* run `deprecated` ui test only when `gil-refs` as disabled
2024-03-08 00:28:11 +00:00
Thomas Tanon
fbd531195a
PyAddToModule: Properly propagate initialization error ( #3919 )
...
Better than panics
2024-03-06 18:20:02 +00:00
David Hewitt
57bbc32e7c
add `experimental-async` feature ( #3931 )
...
* add `experimental-async` feature
* gate async doctests on feature
2024-03-06 00:54:45 +00:00
Thomas Tanon
fe84fed966
Allow inline struct, enum, fn and mod inside of declarative modules ( #3902 )
...
* Inline struct, enum, fn and mod inside of declarative modules
* remove news fragment
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-06 00:31:56 +00:00
Bruno Kolenbrander
4114dcb1a0
Thread pyo3's path through the builder functions ( #3907 )
...
* Thread pyo3's path through the builder functions
* preserve span of pyo3_path
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-03-04 07:54:04 +00:00
Icxolu
70a7aa808d
deprecate the use of `PyCell` in favor of `Bound` and `Py` ( #3916 )
...
* deprecate the use of `PyCell` in favor of `Bound` and `Py`
* update `FromPyObject` for `T: PyClass + Clone` impl
* move `PyCell` deprecation to the `gil-refs` feature gate and add a migration note
2024-03-03 14:47:25 +00:00
David Hewitt
2e56f659ed
split `PyCell` and `PyClassObject` concepts ( #3917 )
...
* add test for refguard ref counting
* split `PyCell` and `PyClassObject` concepts
* rework `create_cell` to `create_class_object`
* Apply suggestions from code review
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
* review: Icxolu feedback
---------
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-03-03 07:00:59 +00:00
Icxolu
1c5265e1c2
deprecate `from_borrowed_ptr` methods ( #3915 )
...
* deprecate `from_borrowed_ptr` methods
This deprecates the methods on the `Python`
marker, aswell as `FromPyPointer`
* use `BoundRef` to defer ref cnt inc until after the error case
2024-03-01 20:51:53 +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
Matthew Neeley
a15e4b1a11
Allow pymodule functions to take a single Bound<'_, PyModule> arg ( #3905 )
2024-02-27 22:24:14 +00:00
Icxolu
6f03a5464f
cleans up `PyCFunction::internal_new` ( #3910 )
...
This deduplicates some code around `PyCFunction::internal_new`
2024-02-27 22:15:35 +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
8e2219b0d9
silence non-local-definitions nightly lint ( #3901 )
...
* silence non-local-definitions nightly lint
* add newsfragment
* add FIXMEs for `non_local_definitions`
* also allow `non_local_definitions` in doctests
2024-02-26 20:28:04 +00:00
Icxolu
7c10ff4327
allow `Bound<'_, T>` in #[pymethods] `self` position ( #3896 )
...
* allow `Bound<'_, T>` in #[pymethods] `self` position
* rename `TryFromPyCell` -> `TryFromBoundRef`
* remove unneccessary unsafe
2024-02-25 07:13:36 +00:00
Thomas Tanon
e0e3981e17
#[pymodule] mod some_module { ... } v3 ( #3815 )
...
* #[pymodule] mod some_module { ... } v3
Based on #2367 and #3294
Allows to export classes, native classes, functions and submodules and provide an init function
See test/test_module.rs for an example
Future work:
- update examples, README and guide
- investigate having #[pyclass] and #[pyfunction] directly in the #[pymodule]
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Georg Brandl <georg@python.org>
* tests: group exported imports
* Consolidate pymodule macro code to avoid duplicates
* Makes pymodule_init take Bound<'_, PyModule>
* Renames #[pyo3] to #[pymodule_export]
* Gates #[pymodule] mod behind the experimental-declarative-modules feature
* Properly fails on functions inside of declarative modules
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Georg Brandl <georg@python.org>
2024-02-24 13:50:18 +00:00
David Hewitt
fbf2e91914
macros: exact dependency on `pyo3-build-config` ( #3889 )
2024-02-23 12:30:46 +00:00
Lily Foote
22a23ffb31
Tidy some usage of `py.from_borrowed_ptr` and `py.from_borrowed_ptr_or_opt` ( #3877 )
...
* Tidy some usage of py.from_borrowed_ptr
* Add BoundRef::ref_from_ptr_or_opt
2024-02-22 23:06:55 +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
Lily Foote
b4dc854585
Convert LazyTypeObject to use the Bound API ( #3855 )
2024-02-18 22:01:50 +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
9902633116
allow `from_py_with` on function args to take a `fn(&Bound) -> PyResult` ( #3837 )
2024-02-14 22:03:04 +00:00
David Hewitt
f5eafe23f2
add maximum Python version check ( #3821 )
...
* add maximum Python version check
* restore dependency of `pyo3-macros-backend` on `pyo3-build-config`
* fix clippy-all noxfile job
2024-02-13 21:52:53 +00:00
Icxolu
fbfeb2ff03
update `#[derive(FromPyObject)]` to use `extract_bound` ( #3828 )
...
* update `#[derive(FromPyObject)]` to use `extract_bound`
* type inference for `from_py_with` using function pointers
2024-02-13 00:09:41 +00:00
David Hewitt
0d4df9c19d
adjust `FromPyObject` implementations to always use `'py` lifetime
2024-02-04 14:22:03 +00: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
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
46c3190a17
clean up remnants of deprecated & removed features
2023-12-29 13:36:46 +00:00
Adam Reichold
83697f0c62
Also replace IterANextOutput by autoref-based specialization to allow returning arbitrary values
2023-12-20 09:56:16 +01:00
Adam Reichold
ca7d90dcf3
Replace IterNextOutput by autoref-based specialization to allow returning arbitrary values
2023-12-20 09:56:16 +01:00
Adam Reichold
d75d4bdf81
Fix some holdouts from using argument holders for lifetime extensions.
2023-12-20 09:56:16 +01:00
Adam Reichold
f03ccf204c
Also apply holder lifetime extension to slot implementations.
2023-12-19 16:29:43 +01:00
Adam Reichold
27019b5523
Use local variables to extend lifetime of holder references.
2023-12-19 16:21:18 +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
e62e6cad5d
Merge pull request #3603 from davidhewitt/0.19-deprecations
...
remove all functionality deprecated in 0.19
2023-11-28 06:47:30 +00:00
David Hewitt
53311a90eb
Merge pull request #3602 from davidhewitt/dead-kws
...
remove some unused keyword declarations
2023-11-28 06:45:43 +00:00
Alex Gaynor
fae209419c
fixes #3561 -- silence new clippy warning
2023-11-27 17:06:59 -05:00
David Hewitt
5c6d49084f
remove all functionality deprecated in 0.19
2023-11-27 22:02:19 +00:00
David Hewitt
e76797a1d6
remove some unused keyword declarations
2023-11-27 21:32:01 +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
abe518d164
Merge pull request #3586 from davidhewitt/semver-checks-v2
...
enable cargo-semver-checks, try 2
2023-11-20 07:07:44 +00:00
David Hewitt
7b07d6d21b
Merge pull request #3578 from davidhewitt/typed-helpers
...
Change return types of `py.None()`, `py.NotImplemented()` and `py.Ellipsis()` to typed singletons
2023-11-20 07:07:12 +00:00
David Hewitt
4a43b2f454
bump version to 0.21.0-dev
2023-11-19 06:41:10 +00: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
a9305ab389
ci: move lints to new 1.74 cargo.toml tables
2023-11-17 15:41:52 +00:00
David Hewitt
c77deee18e
release: 0.20.0
2023-10-11 14:39:19 +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
b3ee70db40
refactor `parse_fn_type`
2023-10-08 21:31:59 +01:00
David Hewitt
1158c08f42
error on passing arguments to `#[new]` and similar attributes
2023-10-08 21:31:59 +01: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
6c0386ec7e
remove branches for dead `call` and `init` attrs
2023-09-27 08:52:56 +01:00
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