Skip to content

Commit

Permalink
Update to PyO3 0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jun 25, 2024
1 parent be4ba70 commit 79da67d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 157 deletions.
146 changes: 14 additions & 132 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name = "rlbot_flatbuffers"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.21.0"
pyo3 = { version = "0.22.0", features = ["py-clone"] }
serde = "1.0.197"
flatbuffers = "24.3.25"
get-size = { version = "0.1.4", features = ["derive"] }
Expand Down
14 changes: 5 additions & 9 deletions codegen/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ impl EnumBindGenerator {
);
write_str!(self, " }");
}

fn generate_enum_hash_method(&mut self) {
write_str!(self, " pub fn __hash__(&self) -> u64 {");
write_str!(self, " crate::hash_u8(*self as u8)");
write_str!(self, " }");
}
}

impl Generator for EnumBindGenerator {
Expand Down Expand Up @@ -247,8 +241,11 @@ impl Generator for EnumBindGenerator {

fn generate_definition(&mut self) {
write_str!(self, "#[allow(non_camel_case_types)]");
write_str!(self, "#[pyclass(module = \"rlbot_flatbuffers\", frozen)]");
write_str!(self, "#[derive(Debug, Default, Clone, Copy)]");
write_str!(
self,
"#[pyclass(module = \"rlbot_flatbuffers\", frozen, hash, eq, eq_int)]"
);
write_str!(self, "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]");
write_fmt!(self, "pub enum {} {{", self.struct_name);
write_str!(self, " #[default]");

Expand Down Expand Up @@ -329,7 +326,6 @@ impl Generator for EnumBindGenerator {
self.generate_repr_method();
write_str!(self, "");

self.generate_enum_hash_method();
write_str!(self, "}");
write_str!(self, "");
}
Expand Down
4 changes: 2 additions & 2 deletions codegen/pyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
write_str!(file, " def __int__(self) -> int: ...");
write_fmt!(
file,
" def __richcmp__(self, other: {type_name}, op: int) -> bool: ..."
" def __eq__(self, other: {type_name}) -> bool: ..."
);
write_str!(file, " def __hash__(self) -> str: ...");
}
PythonBindType::Struct(gen) => {
let mut python_types = Vec::new();
Expand Down Expand Up @@ -216,7 +217,6 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {

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

if !(matches!(item, PythonBindType::Union { .. })) {
write_str!(file, " def pack(self) -> bytes: ...");
Expand Down
2 changes: 1 addition & 1 deletion codegen/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl Generator for StructBindGenerator {
);

if self.types.is_empty() {
write_str!(self, "#[derive(Debug, Default, Clone)]");
write_str!(self, "#[derive(Debug, Default, Clone, Copy)]");
write_fmt!(self, "pub struct {} {{}}", self.struct_name);
write_str!(self, "");
return;
Expand Down
15 changes: 3 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ mod python;

use pyo3::{create_exception, exceptions::PyValueError, prelude::*, types::PyBytes, PyClass};
use python::*;
use std::{
hash::{DefaultHasher, Hash, Hasher},
panic::Location,
};
use std::panic::Location;

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

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

pub fn hash_u8(num: u8) -> u64 {
let mut hasher = DefaultHasher::new();
num.hash(&mut hasher);
hasher.finish()
}

pub trait FromGil<T> {
fn from_gil(py: Python, obj: T) -> Self;
}
Expand Down Expand Up @@ -113,7 +104,7 @@ pub const fn bool_to_str(b: bool) -> &'static str {
}
}

#[derive(Debug, Clone, FromPyObject)]
#[derive(Debug, FromPyObject)]
pub enum Floats {
Flat(Py<Float>),
Num(f32),
Expand All @@ -134,7 +125,7 @@ impl FromGil<Floats> for Py<Float> {
}
}

#[derive(Debug, Clone, FromPyObject)]
#[derive(Debug, FromPyObject)]
pub enum Bools {
Flat(Py<Bool>),
Num(bool),
Expand Down

0 comments on commit 79da67d

Please sign in to comment.