Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nightly ci #4385

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ For simple cases where a member variable is just read and written with no side e

```rust
# use pyo3::prelude::*;
# #[allow(dead_code)]
#[pyclass]
struct MyClass {
#[pyo3(get, set)]
Expand Down Expand Up @@ -1360,6 +1361,7 @@ The `#[pyclass]` macro expands to roughly the code seen below. The `PyClassImplC
# #[cfg(not(feature = "multiple-pymethods"))] {
# use pyo3::prelude::*;
// Note: the implementation differs slightly with the `multiple-pymethods` feature enabled.
# #[allow(dead_code)]
struct MyClass {
# #[allow(dead_code)]
num: i32,
Expand Down
10 changes: 10 additions & 0 deletions guide/src/class/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ To automatically generate the `__str__` implementation using a `Display` trait i
# use std::fmt::{Display, Formatter};
# use pyo3::prelude::*;
#
# #[allow(dead_code)]
# #[pyclass(str)]
# struct Coordinate {
x: i32,
Expand All @@ -102,6 +103,7 @@ For convenience, a shorthand format string can be passed to `str` as `str="<form
```rust
# use pyo3::prelude::*;
#
# #[allow(dead_code)]
# #[pyclass(str="({x}, {y}, {z})")]
# struct Coordinate {
x: i32,
Expand All @@ -122,6 +124,7 @@ the subclass name. This is typically done in Python code by accessing
# use pyo3::prelude::*;
# use pyo3::types::PyString;
#
# #[allow(dead_code)]
# #[pyclass]
# struct Number(i32);
#
Expand Down Expand Up @@ -150,6 +153,7 @@ use std::hash::{Hash, Hasher};

# use pyo3::prelude::*;
#
# #[allow(dead_code)]
# #[pyclass]
# struct Number(i32);
#
Expand All @@ -170,6 +174,7 @@ method it should not define a `__hash__()` operation either"
```rust
# use pyo3::prelude::*;
#
# #[allow(dead_code)]
#[pyclass(frozen, eq, hash)]
#[derive(PartialEq, Hash)]
struct Number(i32);
Expand Down Expand Up @@ -213,6 +218,7 @@ use pyo3::class::basic::CompareOp;

# use pyo3::prelude::*;
#
# #[allow(dead_code)]
# #[pyclass]
# struct Number(i32);
#
Expand All @@ -239,6 +245,7 @@ use pyo3::class::basic::CompareOp;

# use pyo3::prelude::*;
#
# #[allow(dead_code)]
# #[pyclass]
# struct Number(i32);
#
Expand Down Expand Up @@ -285,6 +292,7 @@ To implement `__eq__` using the Rust [`PartialEq`] trait implementation, the `eq
```rust
# use pyo3::prelude::*;
#
# #[allow(dead_code)]
#[pyclass(eq)]
#[derive(PartialEq)]
struct Number(i32);
Expand All @@ -295,6 +303,7 @@ To implement `__lt__`, `__le__`, `__gt__`, & `__ge__` using the Rust `PartialOrd
```rust
# use pyo3::prelude::*;
#
# #[allow(dead_code)]
#[pyclass(eq, ord)]
#[derive(PartialEq, PartialOrd)]
struct Number(i32);
Expand All @@ -307,6 +316,7 @@ We'll consider `Number` to be `True` if it is nonzero:
```rust
# use pyo3::prelude::*;
#
# #[allow(dead_code)]
# #[pyclass]
# struct Number(i32);
#
Expand Down
1 change: 1 addition & 0 deletions guide/src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ done with the `crate` attribute:
# use pyo3::prelude::*;
# pub extern crate pyo3;
# mod reexported { pub use ::pyo3; }
# #[allow(dead_code)]
#[pyclass]
#[pyo3(crate = "reexported::pyo3")]
struct MyClass;
Expand Down
1 change: 1 addition & 0 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub trait ToPyObject {
/// ```rust
/// use pyo3::prelude::*;
///
/// # #[allow(dead_code)]
/// #[pyclass]
/// struct Number {
/// #[pyo3(get, set)]
Expand Down
5 changes: 4 additions & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ macro_rules! pyobject_native_type_named (
#[macro_export]
macro_rules! pyobject_native_static_type_object(
($typeobject:expr) => {
|_py| unsafe { ::std::ptr::addr_of_mut!($typeobject) }
|_py| {
#[allow(unused_unsafe)] // https://github.com/rust-lang/rust/pull/125834
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great, so it looks like one day we won't need the allow at all. Great investigation!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably gonna be a while until we're at MSRV 1.82, but eventually is better than never 😆

unsafe { ::std::ptr::addr_of_mut!($typeobject) }
}
};
);

Expand Down
2 changes: 1 addition & 1 deletion tests/test_declarative_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ValueClass {
}

#[pyclass(module = "module")]
struct LocatedClass {}
pub struct LocatedClass {}

#[pyfunction]
fn double(x: usize) -> usize {
Expand Down
1 change: 1 addition & 0 deletions tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ make_struct_using_macro!(MyBaseClass, "MyClass");
macro_rules! set_extends_via_macro {
($class_name:ident, $base_class:path) => {
// Try and pass a variable into the extends parameter
#[allow(dead_code)]
#[pyclass(extends=$base_class)]
struct $class_name {}
};
Expand Down
Loading