Skip to content

Commit 1c89ce9

Browse files
committed
Fix update_list
Testing of `unpack_with`
1 parent b9a58b3 commit 1c89ce9

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot_flatbuffers"
3-
version = "0.14.0"
3+
version = "0.14.1"
44
edition = "2024"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot_flatbuffers_py"

pytest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ def random_script_config():
159159
data = ballPred.pack()
160160
print(f"BallPrediction size: {len(data)} bytes")
161161

162+
# verify unpack_with method
163+
emptyBallPred = BallPrediction()
164+
data = emptyBallPred.pack()
165+
166+
ballPred.unpack_with(data)
167+
assert len(ballPred.slices) == 0
168+
169+
fullBallPred = BallPrediction([PredictionSlice(t / 120) for t in range(6 * 120)])
170+
data = fullBallPred.pack()
171+
172+
ballPred.unpack_with(data)
173+
assert len(ballPred.slices) == 6 * 120
174+
175+
halfBallPred = BallPrediction(
176+
[PredictionSlice(t / 120 + 1) for t in range(3 * 120)]
177+
)
178+
data = halfBallPred.pack()
179+
180+
ballPred.unpack_with(data)
181+
assert len(ballPred.slices) == 3 * 120
182+
183+
for i, slice in enumerate(ballPred.slices):
184+
assert slice.game_seconds - (i / 120 + 1) < 1e-6
185+
162186
print()
163187

164188
print("Running quick benchmark...")

src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ pub mod generated;
1515
#[allow(clippy::enum_variant_names, clippy::useless_conversion, unused_imports)]
1616
mod python;
1717

18-
use pyo3::{PyClass, create_exception, exceptions::PyValueError, prelude::*, types::*};
18+
use pyo3::{
19+
PyClass, create_exception, exceptions::PyValueError, prelude::*,
20+
pyclass::boolean_struct::False, types::*,
21+
};
1922
use python::*;
2023
use std::{panic::Location, path::MAIN_SEPARATOR};
2124

@@ -144,9 +147,7 @@ pub trait UnpackFrom<T> {
144147
pub fn update_list<T, U>(py: Python, items: Borrowed<PyList>, flat_t: Vec<T>)
145148
where
146149
T: IntoGil<U>,
147-
U: pyo3::PyClass<Frozen = pyo3::pyclass::boolean_struct::False>
148-
+ Into<PyClassInitializer<U>>
149-
+ UnpackFrom<T>,
150+
U: pyo3::PyClass<Frozen = False> + Into<PyClassInitializer<U>> + UnpackFrom<T>,
150151
{
151152
let scripts_len = flat_t.len();
152153
let mut script_iter = flat_t.into_iter();
@@ -159,8 +160,9 @@ where
159160
.borrow_mut()
160161
.unpack_from(py, item),
161162
None => {
162-
for i in scripts_len..items.len() {
163-
items.del_item(i).unwrap();
163+
let items_len = items.len();
164+
for i in 0..items_len - scripts_len {
165+
items.del_item(items_len - i - 1).unwrap();
164166
}
165167
return;
166168
}

0 commit comments

Comments
 (0)