diff --git a/Cargo.lock b/Cargo.lock index 4acaa68..8968e69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "attribute-derive" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36f18fc482cf559bca9efe778ba2fd0d1c16a31d5d24a2c886ed16b2d217e454" +checksum = "f1800e974930e9079c965b9ffbcb6667a40401063a26396c7b4f15edc92da690" dependencies = [ "attribute-derive-macro", "derive-where", @@ -18,9 +18,9 @@ dependencies = [ [[package]] name = "attribute-derive-macro" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85958950e587256a16c72325ff3c4f3e4db25999173e9ca2864665be84ff63b" +checksum = "5d908eb786ef94296bff86f90130b3b748b49401dc81fd2bb8b3dccd44cfacbd" dependencies = [ "collection_literals", "interpolator", @@ -115,9 +115,9 @@ checksum = "71dd52191aae121e8611f1e8dc3e324dd0dd1dee1e6dd91d10ee07a3cfb4d9d8" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "manyhow" @@ -176,18 +176,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15ee168e30649f7f234c3d49ef5a7a6cbf5134289bc46c29ff3155fa3221c225" +checksum = "7ebb0c0cc0de9678e53be9ccf8a2ab53045e6e3a8be03393ceccc5e7396ccb40" dependencies = [ "cfg-if", "indoc", @@ -203,9 +203,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e61cef80755fe9e46bb8a0b8f20752ca7676dcc07a5277d8b7768c6172e529b3" +checksum = "80e3ce69c4ec34476534b490e412b871ba03a82e35604c3dfb95fcb6bfb60c09" dependencies = [ "once_cell", "target-lexicon", @@ -213,9 +213,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ce096073ec5405f5ee2b8b31f03a68e02aa10d5d4f565eca04acc41931fa1c" +checksum = "3b09f311c76b36dfd6dd6f7fa6f9f18e7e46a1c937110d283e80b12ba2468a75" dependencies = [ "libc", "pyo3-build-config", @@ -223,9 +223,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2440c6d12bc8f3ae39f1e775266fa5122fd0c8891ce7520fa6048e683ad3de28" +checksum = "fd4f74086536d1e1deaff99ec0387481fb3325c82e4e48be0e75ab3d3fcb487a" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -235,9 +235,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.3" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be962f0e06da8f8465729ea2cb71a416d2257dff56cbe40a70d3e62a93ae5d1" +checksum = "9e77dfeb76b32bbf069144a5ea0a36176ab59c8db9ce28732d0f06f096bbfbc8" dependencies = [ "heck", "proc-macro2", @@ -279,7 +279,7 @@ dependencies = [ [[package]] name = "rlbot-flatbuffers-py" -version = "0.10.0" +version = "0.11.1" dependencies = [ "flatbuffers", "get-size", @@ -304,18 +304,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -330,9 +330,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.79" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 5bc23b1..e93b64d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rlbot-flatbuffers-py" -version = "0.11.0" +version = "0.11.1" edition = "2021" description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers" repository = "https://github.com/VirxEC/rlbot_flatbuffers_py" @@ -19,7 +19,7 @@ name = "rlbot_flatbuffers" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.22.0", features = ["py-clone"] } +pyo3 = { version = "0.23.0", features = ["py-clone"] } serde = "1.0.197" flatbuffers = "24.3.25" # get-size appears to be unmaintained but it's too useful here diff --git a/codegen/structs.rs b/codegen/structs.rs index 3db77ef..78551ae 100644 --- a/codegen/structs.rs +++ b/codegen/structs.rs @@ -554,13 +554,13 @@ impl StructBindGenerator { self, " fn __match_args__(py: Python) -> Bound {" ); - write_str!(self, " pyo3::types::PyTuple::new_bound(py, ["); + write_str!(self, " pyo3::types::PyTuple::new(py, ["); for variable_info in &self.types { write_fmt!(self, " \"{}\",", variable_info.name); } - write_str!(self, " ])"); + write_str!(self, " ]).unwrap()"); write_str!(self, " }"); } @@ -613,14 +613,11 @@ impl StructBindGenerator { write_str!(self, " let offset = flat_t.pack(&mut builder);"); write_str!(self, " builder.finish(offset, None);"); write_str!(self, ""); - write_str!( - self, - " PyBytes::new_bound(py, builder.finished_data())" - ); + write_str!(self, " PyBytes::new(py, builder.finished_data())"); } else { write_str!(self, " let item = flat_t.pack();"); write_str!(self, ""); - write_str!(self, " PyBytes::new_bound(py, &item.0)"); + write_str!(self, " PyBytes::new(py, &item.0)"); } write_str!(self, " }"); @@ -797,9 +794,7 @@ impl Generator for StructBindGenerator { let variable_name = variable_info.name.as_str(); let end = match &variable_info.rust_type { - RustType::Vec(InnerVecType::U8) => { - Cow::Borrowed("PyBytes::new_bound(py, &[]).unbind()") - } + RustType::Vec(InnerVecType::U8) => Cow::Borrowed("PyBytes::new(py, &[]).unbind()"), RustType::Vec(_) => Cow::Borrowed("Vec::new()"), RustType::Option(_, _) => Cow::Borrowed("None"), RustType::Union(inner_type) @@ -869,7 +864,7 @@ impl Generator for StructBindGenerator { RustType::Vec(InnerVecType::U8) => { write_fmt!( self, - " {variable_name}: PyBytes::new_bound(py, &flat_t.{variable_name}).unbind()," + " {variable_name}: PyBytes::new(py, &flat_t.{variable_name}).unbind()," ) } RustType::Vec(InnerVecType::String | InnerVecType::Base(_)) => { diff --git a/codegen/unions.rs b/codegen/unions.rs index 3ae6737..0cb54d3 100644 --- a/codegen/unions.rs +++ b/codegen/unions.rs @@ -33,7 +33,7 @@ impl UnionBindGenerator { let file_contents = vec![ Cow::Borrowed("use crate::{generated::rlbot::flat, FromGil};"), - Cow::Borrowed("use pyo3::{pyclass, pymethods, Py, PyObject, Python, ToPyObject};"), + Cow::Borrowed("use pyo3::{pyclass, pymethods, Bound, Py, PyObject, Python};"), Cow::Borrowed(""), ]; @@ -61,10 +61,7 @@ impl UnionBindGenerator { write_str!(self, " }"); write_str!(self, ""); write_str!(self, " #[getter(item)]"); - write_str!( - self, - " pub fn get(&self, py: Python) -> Option {" - ); + write_str!(self, " pub fn get(&self) -> Option<&PyObject> {"); write_str!(self, " match self.item.as_ref() {"); for variable_info in &self.types { @@ -75,7 +72,7 @@ impl UnionBindGenerator { } else { write_fmt!( self, - " Some({}Union::{variable_name}(item)) => Some(item.to_object(py)),", + " Some({}Union::{variable_name}(item)) => Some(item.as_any()),", self.struct_name ); } diff --git a/flatbuffers-schema b/flatbuffers-schema index 4b20b67..a01a99d 160000 --- a/flatbuffers-schema +++ b/flatbuffers-schema @@ -1 +1 @@ -Subproject commit 4b20b67a644aaa1455cccfc4194cd38a616bc9ef +Subproject commit a01a99dedbe9f7b58e3f91191dbd20e90c476d84 diff --git a/pytest.py b/pytest.py index 29445dc..ea34987 100644 --- a/pytest.py +++ b/pytest.py @@ -17,7 +17,7 @@ def random_player_config(): return PlayerConfiguration( variety=Psyonix(PsyonixSkill.AllStar), name=random_string(), - location=random_string(), + root_dir=random_string(), run_command=random_string(), loadout=PlayerLoadout( loadout_paint=LoadoutPaint(), @@ -135,7 +135,7 @@ def random_script_config(): renderPolyLine = RenderMessage( PolyLine3D( [Vector3() for _ in range(2048)], - Color(255), + Color(a=255), ), ) diff --git a/src/lib.rs b/src/lib.rs index 9ad3c0f..a194594 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ clippy::derivable_impls, clippy::unnecessary_cast, clippy::size_of_in_element_count, + clippy::needless_lifetimes, clippy::too_long_first_doc_paragraph, non_snake_case, unused_imports @@ -88,8 +89,9 @@ impl>> PyDefault for T { } } +#[inline(never)] pub fn get_empty_pybytes() -> Py { - Python::with_gil(|py| PyBytes::new_bound(py, &[]).unbind()) + Python::with_gil(|py| PyBytes::new(py, &[]).unbind()) } pub fn get_py_default() -> Py { @@ -97,11 +99,13 @@ pub fn get_py_default() -> Py { } #[must_use] +#[inline(never)] pub fn none_str() -> String { String::from("None") } #[must_use] +#[inline(never)] pub const fn bool_to_str(b: bool) -> &'static str { if b { "True" @@ -160,7 +164,7 @@ macro_rules! pynamedmodule { fn $name(py: Python, m: Bound) -> PyResult<()> { $(m.add_class::<$class_name>()?);*; $(m.add($var_name, $value)?);*; - $(m.add(stringify!($except), py.get_type_bound::<$except>())?);*; + $(m.add(stringify!($except), py.get_type::<$except>())?);*; Ok(()) } };