Skip to content

Commit 7853bc3

Browse files
committed
Update to newest PyO3
1 parent baf21b7 commit 7853bc3

File tree

7 files changed

+46
-50
lines changed

7 files changed

+46
-50
lines changed

Cargo.lock

+26-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot-flatbuffers-py"
3-
version = "0.11.0"
3+
version = "0.11.1"
44
edition = "2021"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"
@@ -19,7 +19,7 @@ name = "rlbot_flatbuffers"
1919
crate-type = ["cdylib"]
2020

2121
[dependencies]
22-
pyo3 = { version = "0.22.0", features = ["py-clone"] }
22+
pyo3 = { version = "0.23.0", features = ["py-clone"] }
2323
serde = "1.0.197"
2424
flatbuffers = "24.3.25"
2525
# get-size appears to be unmaintained but it's too useful here

codegen/structs.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,13 @@ impl StructBindGenerator {
554554
self,
555555
" fn __match_args__(py: Python) -> Bound<pyo3::types::PyTuple> {"
556556
);
557-
write_str!(self, " pyo3::types::PyTuple::new_bound(py, [");
557+
write_str!(self, " pyo3::types::PyTuple::new(py, [");
558558

559559
for variable_info in &self.types {
560560
write_fmt!(self, " \"{}\",", variable_info.name);
561561
}
562562

563-
write_str!(self, " ])");
563+
write_str!(self, " ]).unwrap()");
564564
write_str!(self, " }");
565565
}
566566

@@ -613,14 +613,11 @@ impl StructBindGenerator {
613613
write_str!(self, " let offset = flat_t.pack(&mut builder);");
614614
write_str!(self, " builder.finish(offset, None);");
615615
write_str!(self, "");
616-
write_str!(
617-
self,
618-
" PyBytes::new_bound(py, builder.finished_data())"
619-
);
616+
write_str!(self, " PyBytes::new(py, builder.finished_data())");
620617
} else {
621618
write_str!(self, " let item = flat_t.pack();");
622619
write_str!(self, "");
623-
write_str!(self, " PyBytes::new_bound(py, &item.0)");
620+
write_str!(self, " PyBytes::new(py, &item.0)");
624621
}
625622

626623
write_str!(self, " }");
@@ -797,9 +794,7 @@ impl Generator for StructBindGenerator {
797794
let variable_name = variable_info.name.as_str();
798795

799796
let end = match &variable_info.rust_type {
800-
RustType::Vec(InnerVecType::U8) => {
801-
Cow::Borrowed("PyBytes::new_bound(py, &[]).unbind()")
802-
}
797+
RustType::Vec(InnerVecType::U8) => Cow::Borrowed("PyBytes::new(py, &[]).unbind()"),
803798
RustType::Vec(_) => Cow::Borrowed("Vec::new()"),
804799
RustType::Option(_, _) => Cow::Borrowed("None"),
805800
RustType::Union(inner_type)
@@ -869,7 +864,7 @@ impl Generator for StructBindGenerator {
869864
RustType::Vec(InnerVecType::U8) => {
870865
write_fmt!(
871866
self,
872-
" {variable_name}: PyBytes::new_bound(py, &flat_t.{variable_name}).unbind(),"
867+
" {variable_name}: PyBytes::new(py, &flat_t.{variable_name}).unbind(),"
873868
)
874869
}
875870
RustType::Vec(InnerVecType::String | InnerVecType::Base(_)) => {

codegen/unions.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl UnionBindGenerator {
3333

3434
let file_contents = vec![
3535
Cow::Borrowed("use crate::{generated::rlbot::flat, FromGil};"),
36-
Cow::Borrowed("use pyo3::{pyclass, pymethods, Py, PyObject, Python, ToPyObject};"),
36+
Cow::Borrowed("use pyo3::{pyclass, pymethods, Bound, Py, PyObject, Python};"),
3737
Cow::Borrowed(""),
3838
];
3939

@@ -61,10 +61,7 @@ impl UnionBindGenerator {
6161
write_str!(self, " }");
6262
write_str!(self, "");
6363
write_str!(self, " #[getter(item)]");
64-
write_str!(
65-
self,
66-
" pub fn get(&self, py: Python) -> Option<PyObject> {"
67-
);
64+
write_str!(self, " pub fn get(&self) -> Option<&PyObject> {");
6865
write_str!(self, " match self.item.as_ref() {");
6966

7067
for variable_info in &self.types {
@@ -75,7 +72,7 @@ impl UnionBindGenerator {
7572
} else {
7673
write_fmt!(
7774
self,
78-
" Some({}Union::{variable_name}(item)) => Some(item.to_object(py)),",
75+
" Some({}Union::{variable_name}(item)) => Some(item.as_any()),",
7976
self.struct_name
8077
);
8178
}

flatbuffers-schema

pytest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def random_player_config():
1717
return PlayerConfiguration(
1818
variety=Psyonix(PsyonixSkill.AllStar),
1919
name=random_string(),
20-
location=random_string(),
20+
root_dir=random_string(),
2121
run_command=random_string(),
2222
loadout=PlayerLoadout(
2323
loadout_paint=LoadoutPaint(),
@@ -135,7 +135,7 @@ def random_script_config():
135135
renderPolyLine = RenderMessage(
136136
PolyLine3D(
137137
[Vector3() for _ in range(2048)],
138-
Color(255),
138+
Color(a=255),
139139
),
140140
)
141141

src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
clippy::derivable_impls,
55
clippy::unnecessary_cast,
66
clippy::size_of_in_element_count,
7+
clippy::needless_lifetimes,
78
clippy::too_long_first_doc_paragraph,
89
non_snake_case,
910
unused_imports
@@ -88,20 +89,23 @@ impl<T: Default + PyClass + Into<PyClassInitializer<T>>> PyDefault for T {
8889
}
8990
}
9091

92+
#[inline(never)]
9193
pub fn get_empty_pybytes() -> Py<PyBytes> {
92-
Python::with_gil(|py| PyBytes::new_bound(py, &[]).unbind())
94+
Python::with_gil(|py| PyBytes::new(py, &[]).unbind())
9395
}
9496

9597
pub fn get_py_default<T: PyDefault>() -> Py<T> {
9698
Python::with_gil(|py| T::py_default(py))
9799
}
98100

99101
#[must_use]
102+
#[inline(never)]
100103
pub fn none_str() -> String {
101104
String::from("None")
102105
}
103106

104107
#[must_use]
108+
#[inline(never)]
105109
pub const fn bool_to_str(b: bool) -> &'static str {
106110
if b {
107111
"True"
@@ -160,7 +164,7 @@ macro_rules! pynamedmodule {
160164
fn $name(py: Python, m: Bound<PyModule>) -> PyResult<()> {
161165
$(m.add_class::<$class_name>()?);*;
162166
$(m.add($var_name, $value)?);*;
163-
$(m.add(stringify!($except), py.get_type_bound::<$except>())?);*;
167+
$(m.add(stringify!($except), py.get_type::<$except>())?);*;
164168
Ok(())
165169
}
166170
};

0 commit comments

Comments
 (0)