Commit Graph

1056 Commits

Author SHA1 Message Date
David Hewitt 8652ac8e1c
remove all functionality deprecated in 0.20 (#4322)
* remove all functionality deprecated in 0.20

* bump version to 0.23.0-dev

* undo unintended revert

* fixup UI test
2024-07-09 16:44:27 +00:00
Alex Gaynor e73112f3f6
Automatically treat nested modules as submodules (#4308)
fixes #4286
2024-07-09 12:15:12 +00:00
David Hewitt 186c7d3315
docs: improve signposting to bound and traits (#4325)
* docs: improve signposting to bound and traits

* update UI tests
2024-07-09 11:53:11 +00:00
Icxolu 3c155d9fef
remove the gil-ref deprecations infrastructure (#4320) 2024-07-08 13:40:27 +00:00
Alex Gaynor 9afc38ae41
fixes #4285 -- allow full-path to pymodule with nested declarative modules (#4288) 2024-07-05 09:16:06 +00:00
David Hewitt 0af0227834
fix deprecation warning for trailing optional on `#[setter]` functions (#4304)
* fix deprecation warning for trailing optional on `#[setter]` functions

* add comment
2024-07-04 10:08:22 +00:00
Alex Gaynor ccd04475a3
refs #4286 -- allow setting submodule on declarative pymodules (#4301) 2024-07-02 11:24:47 +00:00
David Hewitt 91d8683814
improve deprecation message on implicit trailing optionals (#4282) 2024-06-24 13:38:33 +00:00
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
David Hewitt ca82681615
ci: minor cleanups following 1.63 MSRV (#4239)
* ci: minor cleanups following 1.63 MSRV

* correct `invalid_pymethods_duplicates` UI test

* fix `nightly` feature
2024-06-21 07:02:31 +00:00
Bruno Kolenbrander b25b3b3a7b
Improve the span and message for return types of pymethod/functions (#4220)
* Improve the span and message for return types of pymethod/functions

* Don't pass the span

* fixup trybuild output

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-06-20 09:23:40 +00:00
WÁNG Xuěruì e6b2216b04
Add several missing wrappers to PyAnyMethods (#4264) 2024-06-20 08:16:06 +00:00
David Hewitt 0e142f05dd
add `c_str!` macro to create `&'static CStr` (#4255)
* add `c_str!` macro to create `&'static CStr`

* newsfragment, just export as `pyo3::ffi::c_str`

* fix doc link

* fix doc

* further `c_str!` based cleanups

* [review]: mejrs

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>

* rustfmt

* build fixes

* clippy

* allow lint on MSRV

* fix GraalPy import

---------

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2024-06-18 18:09:36 +00:00
Alex Gaynor ddff8bea25
Stabilize declarative modules (#4257) 2024-06-17 01:28:20 +00:00
Code Apprentice 79591f2161
Add error messages for unsupported macro features on compilation (#4194)
* First implementation

* tweak error message wording

* Fix boolean logic

* Remove redundant parens

* Add test for weakref error

* Fix test

* Reword error message

* Add expected error output

* Rinse and repeat for `dict`

* Add test output file

* Ignore Rust Rover config files

* cargo fmt

* Add newsfragment

* Update newsfragments/4194.added.md

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* Use ensure_spanned! macro

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* Use ensure_spanned! macro for weakref error, too

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* Revert "Ignore Rust Rover config files"

This reverts commit 6c8a2eec581ed250ec792d8465772d649b0a3199.

* Update wording for error message

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

* Update weakref error message, too

* Refactor constant to a pyversions module

* Fix compiler errors

* Another wording update

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* And make weakref wording the same

* Fix compiler error due to using weakref in our own code

* Fix after merge

* apply conditional pyclass

* update conditional compilation in tests

---------

Co-authored-by: cojmeister <luqas.c@gmail.com>
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-06-16 10:23:03 +00:00
David Hewitt 9648d595a5
implement `PartialEq<str>` for `Bound<'py, PyString>` (#4245)
* implement `PartialEq<str>` for `Bound<'py, PyString>`

* fixup conditional code

* document equality semantics for `Bound<'_, PyString>`

* fix doc example
2024-06-16 08:19:21 +00:00
David Hewitt 0b2f19b3c9
fix `__dict__` on Python 3.9 with limited API (#4251)
* fix `__dict__` on Python 3.9 with limited API

* [review] Icxolu suggestions

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

* [review] Icxolu

* missing import

---------

Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-06-16 07:57:44 +00:00
Icxolu 5749a08b63
ci: updates for Rust 1.79 (#4244)
* ci: updates for Rust 1.79

* ci: fix beta clippy

* ci: fix `dead_code` warning on nightly
2024-06-13 18:24:13 +00:00
Michael Gilbert b8fb367582
feat: Add 'ord' option for PyClass and corresponding tests (#4202)
* feat: Add 'ord' option for PyClass and corresponding tests

Updated the macros back-end to include 'ord' as an option for PyClass allowing for Python-style ordering comparison of enum variants. Additionally, test cases to verify the proper functioning of this new feature have been introduced.

* update: fix formatting with cargo fmt

* update: documented added feature in newsfragments

* update: updated saved errors for comparison test for invalid pyclass args

* update: removed nested match arms and extended cases for ordering instead

* update: alphabetically ordered entries

* update: added section to class documentation with example for using ord argument.

* refactor: reduced duplication of code using closure to process tokens.

* update: used ensure_spanned macro to emit compile time errors for uses of ord on complex enums or structs, updated test errors for bad compile cases

* fix: remove errant character

* update: added note about PartialOrd being required.

* feat: implemented ordering for structs and complex enums.  Retained the equality logic for simple enums until PartialEq is deprecated.

* update: adjusted compile time error checks for missing PartialOrd implementations.  Refactored growing set of comparison tests for simple and complex enums and structs into separate test file.

* fix: updated with clippy findings

* update: added not to pyclass parameters on ord (assumes that eq will be implemented and merged first)

* update: rebased on main after merging of `eq` feature

* update: format update

* update: update all test output and doc tests

* Update guide/src/class.md

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

* Update pyo3-macros-backend/src/pyclass.rs

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

* Update newsfragments/4202.added.md

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

* Update guide/pyclass-parameters.md

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

* update: added note about `ord` implementation with example.

* fix doc formatting

---------

Co-authored-by: Michael Gilbert <git.3mc1o@aleeas.com>
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
2024-06-07 19:08:53 +00:00
Thomas Tanon 74619143b6
Declarative modules: make sure to emit doc comments and other attributes (#4236)
* Declarative modules: make sure to emmit doc comments and other attributes

* Adds a test

* Apply suggestions from code review

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-06-06 21:19:37 +00:00
Thomas Tanon 11d67b3acc
Automated module= field creation in declarative modules (#4213)
* Automated module= field creation in declarative modules

Sets automatically the "module" field of all contained classes and submodules in a declarative module

Adds the "module" field to pymodule attributes in order to set the name of the parent modules. By default, the module is assumed to be a root module

* fix guide test error

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-06-06 07:54:26 +00:00
A. Cody Schuffelen 93ef056711
Use `Ident::parse_any` for `name` attributes (#4226)
This makes it possible to use rust keywords as the name of python class
methods and standalone functions. For example:

```
struct MyClass {
}

impl MyClass {
    #[new]
    fn new() -> Self {
        MyClass {}
    }

    #[pyo3(name = "struct")]
    fn struct_method(&self) -> usize {
        42
    }
}

fn struct_function() -> usize {
    42
}
```

From the [`syn::Ident`
documentation](https://docs.rs/syn/2.0.66/syn/struct.Ident.html):

> An identifier constructed with `Ident::new` is permitted to be a Rust
keyword, though parsing one through its
[`Parse`](https://docs.rs/syn/2.0.66/syn/parse/trait.Parse.html)
implementation rejects Rust keywords. Use `input.call(Ident::parse_any)`
when parsing to match the behaviour of `Ident::new`.

Fixes issue #4225
2024-06-03 19:45:36 +00:00
Icxolu 7e5884c40b
fix incorrect `__richcmp__` for `eq_int` only simple enums (#4224)
* fix incorrect `__richcmp__` for `eq_int` only simple enums

* add tests for deprecated simple enum eq behavior

* only emit deprecation warning if neither `eq` nor `eq_int` were given

* require `eq` for `eq_int`
2024-06-03 18:49:36 +00:00
Icxolu 36cdeb29c1
fix incorrect raw identifier handling for the `name` attribute of `pyfunction`s (#4229) 2024-06-03 17:32:35 +00:00
liammcinroy b4b780b475
Allow module= attribute in complex enum variants (#4228)
* Allow module= attribute in complex enum variants

* stderr test update

* towncrier

* inherit `module`, rather than specifying everywhere.

* clippy fix
2024-06-03 07:57:04 +00:00
Icxolu a7a5c10b8a
add pyclass `hash` option (#4206)
* add pyclass `hash` option

* add newsfragment

* require `frozen` option for `hash`

* simplify `hash` without `frozen` error message

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* require `eq` for `hash`

* prevent manual `__hash__` with `#pyo3(hash)`

* combine error messages

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-06-01 14:20:20 +00:00
Icxolu d1a7cf400a
add pyclass `eq` option (#4210)
* add pyclass `eq` option

* prevent manual impl of `__richcmp__` or `__eq__` with `#[pyclass(eq)]`

* add simple enum `eq_int` option

* rearrange names to fix deprecation warning

* add newsfragment and migration

* update docs

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-05-31 14:13:30 +00:00
JRRudy1 934c663612
Added `From<Bound<'py, T>>` impl for `PyClassInitializer<T>`. (#4214)
* Added `From<Bound<'py, T>>` impl for PyClassInitializer<T>.

* Added newsfragment entry.

* Added tests for pyclass constructors returning `Py<Self>` and `Bound<Self>`.

* Fixed tests.

* Updated tests to properly cover the new impl.

---------

Co-authored-by: jrudolph <jrudolph@anl.gov>
2024-05-28 01:49:52 +00:00
Bruno Kolenbrander fff053bde7
Emit a better error for abi3 inheritance (#4185)
* Emit a better error for abi3 inheritance

* Update tests/test_compile_error.rs

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-05-17 10:55:41 +00:00
newcomertv 88f2f6f4d5
feat: support pyclass on tuple enums (#4072)
* feat: support pyclass on tuple enums

* cargo fmt

* changelog

* ruff format

* rebase with adaptation for FnArg refactor

* fix class.md from pr comments

* add enum tuple variant getitem implementation

* fmt

* progress toward getitem and len impl on derive pyclass for complex enum tuple

* working getitem and len slots for complex tuple enum pyclass derivation

* refactor code generation

* address PR concerns
- take py from function argument on get_item
- make more general slot def implementation
- remove unnecessary function arguments
- add testcases for uncovered cases including future feature match_args

* add tracking issue

* fmt

* ruff

* remove me

* support match_args for tuple enum

* integrate FnArg now takes Cow

* fix empty and single element tuples

* use impl_py_slot_def for cimplex tuple enum slots

* reverse erroneous doc change

* Address latest comments

* formatting suggestion

* fix :
- clippy beta
- better compile error (+related doc and test)

---------

Co-authored-by: Chris Arderne <chris@translucent.app>
2024-05-17 02:59:00 +00:00
Icxolu 10152a7078
feature gate `PyCell` (#4177)
* feature gate `PyCell`

* feature gate `HasPyGilRef` completely

* bump version
2024-05-12 18:30:08 +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 1e8e09dce3
feature gate `as/into_gil_ref` APIs (Part 3) (#4172) 2024-05-10 17:03:57 +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
Icxolu 7beb64a8ca
allow constructor customization of complex enum variants (#4158)
* allow `#[pyo3(signature = ...)]` on complex enum variants to specify constructor signature

* rename keyword to `constructor`

* review feedback

* add docs in guide

* add newsfragment
2024-05-09 21:08:23 +00:00
Icxolu 635cb8075c
feature gate APIs using `into_gil_ref` (Part 1) (#4160) 2024-05-09 07:58:44 +00:00
Icxolu e835ff0ec3
handle `#[pyo3(from_py_with = ...)]` on dunder (`__magic__`) methods (#4117)
* handle `#[pyo3(from_py_with = ...)]` on dunder (__magic__) methods

* add newsfragment
2024-05-04 07:39:40 +00:00
Icxolu cd3f3ed67c
ci: updates for Rust 1.78 (#4150)
* ci: updates for Rust 1.78

* ci: fix clippy

* restrict `invalid_pymethods_duplicates` to unlimited api with `full`
2024-05-03 07:42:30 +00:00
Icxolu 22c5cff039
feature gate deprecated APIs for `PyErr` and exceptions (#4136) 2024-04-30 16:58:53 +00:00
Alex Gaynor 9e1960ea34
Update MSRV to 1.63 (#4129)
* Bump MSRV to 1.63

* Drop parking_lot in favor of std::sync

* Make portable-atomic dep conditional

* Remove no longer required cfg
2024-04-28 16:11:28 +00:00
Bruno Kolenbrander f5fee94afc
Scope macro imports more tightly (#4088) 2024-04-23 18:01:41 +00:00
Icxolu 03f59eaf45
fix declarative module compile error with `create_exception!` (#4086)
* fix declarative module compile error with `create_exception!`

* add newsfragment
2024-04-16 20:12:18 +00:00
Icxolu cc7e16f4d6
Refactoring of `FnArg` (#4033)
* refactor `FnArg`

* add UI tests

* use enum variant types

* add comment

* remove dead code

* remove last FIXME

* review feedback davidhewitt
2024-04-14 14:19:57 +00:00
Adam Reichold 721100a9e9
Suppress non_local_definitions lint as we often want the non-local effects in macro code (#4074)
* Resolve references to legacy numerical constants and use the associated constants instead

* Suppress non_local_definitions lint as we often want the non-local effects in macro code
2024-04-13 12:59:44 +00:00
Icxolu ee5216f406
fix declarative-modules compile error (#4054)
* fix declarative-modules compile error

* add newsfragment
2024-04-12 06:34:27 +00:00
Icxolu c8b59d7117
add `#[doc(hidden)]` to the Rust module created by `#[pymodule]` (#4067)
* add `#[doc(hidden)]` to the Rust module created by `#[pymodule]`

* add newsfragment
2024-04-12 06:34:08 +00:00
Icxolu 7a00b4d357
add descriptive error msg for `__traverse__` receivers other than `&self` (#4045)
* add descriptive error msg for `__traverse__` receivers other than `self`

* add newsfragment

* improve error message
2024-04-04 19:08:51 +00:00
David Hewitt a4aea230ed
fix compile error for multiple async method arguments (#4035) 2024-04-02 17:43:51 +00:00