* implement PartialEq for Pybool
implement PartialEq for Pybool
* fix failing cargodoc and add changelog file
* Use PR number for change log file
* Add false checking into test
* 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>
* attemp to fix range for st.datetime
* remove example
* try fixing to utc
* make datetime from timestamp tests compare against Python result
---------
Co-authored-by: Cheukting <cheukting.ho@gmail.com>
* Copy pasta implementation from types/string.rs
* changelog
* I think I don't need a special implementation for 3.10 or ABI
* Copy pasta tests
* Fix comment with correct type
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
* Fix implementation
* Use slice in tests
* Try renaming changelog file
* Fix doc example
* Fix doc example
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
---------
Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
* Change `search_lib_dir`'s return type to Result
* add changelog
* add coverage and a hint to `PYO3_CROSS_LIB_DIR`
---------
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
* 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
* 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>
* 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>
* Added `PyRef::as_super` and `PyRefMut::as_super` methods, including docstrings and tests. The implementation of these methods also required adding `#[repr(transparent)]` to the `PyRef` and `PyRefMut` structs.
* Added newsfragment entry.
* Changed the `AsRef<U>`/`AsMut<U>` impls for `PyRef` and `PyRefMut` to use the new `as_super` methods. Added the `PyRefMut::downgrade` associated function for converting `&PyRefMut` to `&PyRef`. Updated tests and docstrings to better demonstrate the new functionality.
* Fixed newsfragment filename.
* Removed unnecessary re-borrows flagged by clippy.
* retrigger checks
* Updated `PyRef::as_super`, `PyRefMut::as_super`, and `PyRefMut::downgrade` to use `.cast()` instead of `as _` pointer casts. Fixed typo.
* Updated `PyRef::as_super` and `PyRefMut::downgrade` to use `ptr_from_ref` for the initial cast to `*const _` instead of `as _` casts.
* Added `pyo3::internal_tricks::ptr_from_mut` function alongside the `ptr_from_ref` added in PR #4240. Updated `PyRefMut::as_super` to use this method instead of `as *mut _`.
* Updated the user guide to recommend `as_super` for accessing the base class instead of `as_ref`, and updated the subsequent example/doctest to demonstrate this functionality.
* Improved tests for the `as_super` methods.
* Updated newsfragment to include additional changes.
* Fixed formatting.
---------
Co-authored-by: jrudolph <jrudolph@anl.gov>
* 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>
* 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>
* 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>
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
* 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`