Commit Graph

499 Commits

Author SHA1 Message Date
David Hewitt a5a3f3f7f2
allow `#[pymodule(...)]` to accept all relevant `#[pyo3(...)]` options (#4330) 2024-07-10 22:38:38 +00:00
David Hewitt 32b6a1aef1
docs: use versioned links from docs to guide (#4331)
* use versioned links from docs to guide

* use standard python version in `guide-build` ci job
2024-07-10 12:30:01 +00:00
David Hewitt 97d60e869b
clean up hygiene tests (#4328) 2024-07-09 21:28:15 +00:00
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
Icxolu 3c155d9fef
remove the gil-ref deprecations infrastructure (#4320) 2024-07-08 13:40:27 +00:00
David Hewitt 59c4fa3f24
release: 0.22.1 (#4314) 2024-07-06 22:00:28 +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
Alex Gaynor f3603a0a48
Avoid generating functions that are only ever const evaluated with declarative modules (#4297)
Refs #4286
2024-07-01 21:54:50 +00:00
jatoben 7c2f5e80de
Don't raise `TypeError` from generated equality method (#4287)
* Don't raise TypeError in derived equality method

* Add newsfragment
2024-06-26 05:41:42 +00:00
David Hewitt 2e2d4404a6
release: 0.22.0 (#4266) 2024-06-24 19:06:42 +00:00
David Hewitt 91d8683814
improve deprecation message on implicit trailing optionals (#4282) 2024-06-24 13:38:33 +00:00
Bruno Kolenbrander 6a0221ba2c
document FnType and refactor FnType::self_arg (#4276) 2024-06-23 10:36:19 +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
Alex Gaynor 9ff3d237c1
Update dependencies to reflect minimal versions (#4272)
Based on testing locally with `rm -f Cargo.lock && cargo +nightly check --tests --all -Z minimal-versions`
2024-06-21 10:05:09 +00:00
Icxolu 56341cbc81
emit c-string literals on Rust 1.77 or later (#4269)
* emit c-string literals on Rust 1.77 or later

* only clone `PyO3CratePath` instead of the whole `Ctx`

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

---------

Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-06-21 08:49:33 +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
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 baae9291cc
Update tests for numpy 2.0 (#4258) 2024-06-17 00:05:55 +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
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
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
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
David Hewitt f3c7b90def
remove function pointer wrappers no longer needed for MSRV (#4167) 2024-05-09 22:22:17 +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 d803f7f8df
store the `FnArg` ident as a `Cow` instead of a reference (#4157)
This allow also storing idents that were generated
as part of the macro instead of only ones the were
present in the source code. This is needed for
example in complex enum tuple variants.
2024-05-08 08:04:42 +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
Bruno Kolenbrander f5fee94afc
Scope macro imports more tightly (#4088) 2024-04-23 18:01:41 +00:00
dependabot[bot] b11174e96d
Update heck requirement from 0.4 to 0.5 (#3966)
* Update heck requirement from 0.4 to 0.5

---
updated-dependencies:
- dependency-name: heck
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* newsfragment

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
2024-04-18 10:22:34 +00:00
David Hewitt 2c205d4586
release notes for 0.21.2 (#4091) 2024-04-18 08:59:02 +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
David Hewitt c1f11fb4bd
release: 0.21.1 (#4032) 2024-04-01 18:51:58 +00:00
Icxolu 8f87b8636d
refactor `#[setter]` argument extraction (#4002) 2024-04-01 12:10:18 +00:00
Weijie Guo 74d9d23ba0
async method should allow args not only receiver (#4015)
* async method should allow args not only receiver

* add changelog md
2024-03-30 08:48:19 +00:00