Skip to content

Commit 79da67d

Browse files
committed
Update to PyO3 0.22
1 parent be4ba70 commit 79da67d

6 files changed

Lines changed: 26 additions & 157 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 132 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name = "rlbot_flatbuffers"
1919
crate-type = ["cdylib"]
2020

2121
[dependencies]
22-
pyo3 = "0.21.0"
22+
pyo3 = { version = "0.22.0", features = ["py-clone"] }
2323
serde = "1.0.197"
2424
flatbuffers = "24.3.25"
2525
get-size = { version = "0.1.4", features = ["derive"] }

codegen/enums.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,6 @@ impl EnumBindGenerator {
206206
);
207207
write_str!(self, " }");
208208
}
209-
210-
fn generate_enum_hash_method(&mut self) {
211-
write_str!(self, " pub fn __hash__(&self) -> u64 {");
212-
write_str!(self, " crate::hash_u8(*self as u8)");
213-
write_str!(self, " }");
214-
}
215209
}
216210

217211
impl Generator for EnumBindGenerator {
@@ -247,8 +241,11 @@ impl Generator for EnumBindGenerator {
247241

248242
fn generate_definition(&mut self) {
249243
write_str!(self, "#[allow(non_camel_case_types)]");
250-
write_str!(self, "#[pyclass(module = \"rlbot_flatbuffers\", frozen)]");
251-
write_str!(self, "#[derive(Debug, Default, Clone, Copy)]");
244+
write_str!(
245+
self,
246+
"#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]"
247+
);
248+
write_str!(self, "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]");
252249
write_fmt!(self, "pub enum {} {{", self.struct_name);
253250
write_str!(self, " #[default]");
254251

@@ -329,7 +326,6 @@ impl Generator for EnumBindGenerator {
329326
self.generate_repr_method();
330327
write_str!(self, "");
331328

332-
self.generate_enum_hash_method();
333329
write_str!(self, "}");
334330
write_str!(self, "");
335331
}

codegen/pyi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
8686
write_str!(file, " def __int__(self) -> int: ...");
8787
write_fmt!(
8888
file,
89-
" def __richcmp__(self, other: {type_name}, op: int) -> bool: ..."
89+
" def __eq__(self, other: {type_name}) -> bool: ..."
9090
);
91+
write_str!(file, " def __hash__(self) -> str: ...");
9192
}
9293
PythonBindType::Struct(gen) => {
9394
let mut python_types = Vec::new();
@@ -216,7 +217,6 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
216217

217218
write_str!(file, " def __str__(self) -> str: ...");
218219
write_str!(file, " def __repr__(self) -> str: ...");
219-
write_str!(file, " def __hash__(self) -> str: ...");
220220

221221
if !(matches!(item, PythonBindType::Union { .. })) {
222222
write_str!(file, " def pack(self) -> bytes: ...");

codegen/structs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl Generator for StructBindGenerator {
596596
);
597597

598598
if self.types.is_empty() {
599-
write_str!(self, "#[derive(Debug, Default, Clone)]");
599+
write_str!(self, "#[derive(Debug, Default, Clone, Copy)]");
600600
write_fmt!(self, "pub struct {} {{}}", self.struct_name);
601601
write_str!(self, "");
602602
return;

src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ mod python;
1414

1515
use pyo3::{create_exception, exceptions::PyValueError, prelude::*, types::PyBytes, PyClass};
1616
use python::*;
17-
use std::{
18-
hash::{DefaultHasher, Hash, Hasher},
19-
panic::Location,
20-
};
17+
use std::panic::Location;
2118

2219
create_exception!(rlbot_flatbuffers, InvalidFlatbuffer, PyValueError, "Invalid FlatBuffer");
2320

@@ -31,12 +28,6 @@ pub fn flat_err_to_py(err: flatbuffers::InvalidFlatbuffer) -> PyErr {
3128
InvalidFlatbuffer::new_err(err_msg)
3229
}
3330

34-
pub fn hash_u8(num: u8) -> u64 {
35-
let mut hasher = DefaultHasher::new();
36-
num.hash(&mut hasher);
37-
hasher.finish()
38-
}
39-
4031
pub trait FromGil<T> {
4132
fn from_gil(py: Python, obj: T) -> Self;
4233
}
@@ -113,7 +104,7 @@ pub const fn bool_to_str(b: bool) -> &'static str {
113104
}
114105
}
115106

116-
#[derive(Debug, Clone, FromPyObject)]
107+
#[derive(Debug, FromPyObject)]
117108
pub enum Floats {
118109
Flat(Py<Float>),
119110
Num(f32),
@@ -134,7 +125,7 @@ impl FromGil<Floats> for Py<Float> {
134125
}
135126
}
136127

137-
#[derive(Debug, Clone, FromPyObject)]
128+
#[derive(Debug, FromPyObject)]
138129
pub enum Bools {
139130
Flat(Py<Bool>),
140131
Num(bool),

0 commit comments

Comments
 (0)