BUG: validation in stochastic/ that survives python -O - #1111
Merged
Gui-FernandesBR merged 1 commit intoAug 8, 2026
Merged
Conversation
`stochastic_model.py` has carried this as a TODO:
# TODO: Stop using assert in production code. Use exceptions instead.
The reason it matters is that the optimiser removes them, so the checks stop
running and malformed input reaches the model:
StochasticModel(obj, mass=("not a number", 0.5))
python AssertionError
python -O accepted, mass = ('not a number', 0.5, <Generator.normal>)
That model then fails somewhere later with something that does not point back
at the tuple that caused it.
Twenty one of them, all in stochastic/: thirteen in stochastic_model.py, three
each in stochastic_environment.py and stochastic_flight.py, one in
stochastic_aero_surfaces.py, and the one in stochastic_parachute.py that RocketPy-Team#1103
did not reach. Converted mechanically through the AST, so the condition and the
message are the ones that were there.
AssertionError is kept rather than swapped for TypeError or ValueError. The
docstrings document it, and callers catching it should keep working. Changing
the type is a separate decision from making the check run at all.
Two kinds of test. One reads each module and fails on a reintroduced `assert`,
which is the mechanism. The other runs a child interpreter under -O, because in
process the assert is still compiled in and the check would pass either way.
Also moves two imports in test_custom_sampler.py to the top of the file, which
pylint flags as C0415 on develop today.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1111 +/- ##
===========================================
+ Coverage 82.18% 82.51% +0.33%
===========================================
Files 122 128 +6
Lines 16355 16617 +262
===========================================
+ Hits 13441 13712 +271
+ Misses 2914 2905 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
thc1006
added a commit
to thc1006/RocketPy
that referenced
this pull request
Aug 8, 2026
Two boundaries on `random_seed` that the docstring implied more of than it should. Both were raised on review. What a seed reproduces is the sampled values. With `include_function_data=True` a record also carries a `Function`'s signature hash and serialised source, which describe the object rather than the value drawn for it, so a run under spawn or forkserver writes different ones for the same inputs. The cross-start-method test measured six such fields and filters exactly them. And it is scoped to one environment. NumPy promises a stream only for the same BitGenerator, seed, call sequence, build and machine, and reserves the right to change what `default_rng` returns. A seed fixes the lineage of a run; it is not an archive format that survives a version bump. Also moves two imports in test_custom_sampler.py to the top of the file. They arrived on develop with the cherry-pick of 23be0ba, which was the version before that fix, and pylint exits 16 on them. RocketPy-Team#1111 does the same thing as part of a wider change; this is here because it is what turns this branch's lint red. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
2 tasks
Gui-FernandesBR
approved these changes
Aug 8, 2026
Gui-FernandesBR
pushed a commit
to thc1006/RocketPy
that referenced
this pull request
Aug 12, 2026
Two boundaries on `random_seed` that the docstring implied more of than it should. Both were raised on review. What a seed reproduces is the sampled values. With `include_function_data=True` a record also carries a `Function`'s signature hash and serialised source, which describe the object rather than the value drawn for it, so a run under spawn or forkserver writes different ones for the same inputs. The cross-start-method test measured six such fields and filters exactly them. And it is scoped to one environment. NumPy promises a stream only for the same BitGenerator, seed, call sequence, build and machine, and reserves the right to change what `default_rng` returns. A seed fixes the lineage of a run; it is not an archive format that survives a version bump. Also moves two imports in test_custom_sampler.py to the top of the file. They arrived on develop with the cherry-pick of 23be0ba, which was the version before that fix, and pylint exits 16 on them. RocketPy-Team#1111 does the same thing as part of a wider change; this is here because it is what turns this branch's lint red. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the TODO at the top of
stochastic_model.py, and the point you raised on #1102:# TODO: Stop using assert in production code. Use exceptions instead.The reason it matters is that the optimiser removes them, so the checks stop running and malformed input reaches the model instead of being refused:
That model then fails somewhere later with something that does not point back at the tuple that caused it.
Twenty one of them, all in
stochastic/:stochastic_model.pystochastic_environment.pystochastic_flight.pystochastic_aero_surfaces.pystochastic_parachute.pyConverted through the AST rather than by hand, so the condition and the message are the ones that were already there.
ruffthen collapsednot (x in y)tonot inwhere it applied.AssertionErroris kept rather than swapped forTypeErrororValueError. The docstrings document it and callers catching it should keep working. Changing the type is a separate decision from making the check run at all, and I would rather not fold the two together.Two kinds of test. One reads each module and fails on a reintroduced
assert, which is the mechanism. The other runs a child interpreter under-O, because in process the assert is still compiled in and an ordinary test passes either way. Reintroducing one assert fails both, which is how I checked they have teeth.Also moves two imports in
test_custom_sampler.pyto the top of the file.pylintreports C0415 on them ondeveloptoday, from the cherry-pick of23be0bab, sopylint rocketpy/ tests/ docs/currently exits 16 rather than 0.Local: ruff and format clean, pylint exit 0, 2086 passed and 44 skipped.