Repository navigation
Commit 6224be7
authored
BUG: accept the callable parachute triggers the docstring promises (#1103)
* BUG: accept the callable parachute triggers the docstring promises
The `or` sat inside the isinstance call rather than beside it:
isinstance(member, (str, int, float) or callable(member))
A non-empty type tuple is truthy, so the expression short-circuited to the
tuple and callable(member) was never evaluated. The check reduced to
isinstance(member, (str, int, float)), and a callable is none of those.
Parachute takes a callable trigger and Flight calls it, and the docstring three
lines above says "a list of callables, string 'apogee' or ints/floats". Only
the stochastic wrapper refused one. The two non-callable forms passed
throughout, which is why the tests never caught it.
Left as an assert to match the other fourteen in these two modules, and because
raising a different type would break anyone catching AssertionError.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* BUG: refuse the trigger forms Parachute cannot use
Moving the `or` let callables through, but left four things the check should
never have accepted.
`["banana"]` passed here and then `Parachute` raised ValueError, so the wrapper
only moved the failure to create time. `[True]` is worse: bool is an int, so it
went through as a height of one metre. `[]` passed because `all([])` is True.
And `numbers.Real` replaces `(int, float)`, which took numpy.float64 because it
subclasses float and refused numpy.int64 because it subclasses neither.
The check is raised rather than asserted. `python -O` strips an assert outright,
and this is the only thing between those triggers and a Parachute that either
refuses them later or misreads them. Still an AssertionError, so nothing that
catches it has to change.
The docstring claimed a tuple form that was never implemented; it now describes
what the code does.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* BUG: do not accept numpy integers the Parachute will refuse
Widening the height check to numbers.Real was the same mistake as accepting
"banana": Parachute checks isinstance(trigger, (int, float)), so numpy.float64
passes because it subclasses float and numpy.int64 raises ValueError because it
subclasses neither. Letting them through here only moved the failure to
create_object.
Back to (int, float), matching that check rather than improving on it, and the
test that asserted numpy.int64 was accepted now asserts both ends refuse it.
The asymmetry is Parachute's rather than this wrapper's and is worth fixing
there, where widening the check would not strand anything downstream.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* TST: use the state length Flight actually passes
The trigger tests built a 14-element state. Flight passes 13:
x y z vx vy vz e0 e1 e2 e3 wx wy wz. Only y[5] is read, so both worked, but
the test is there to document the contract and was documenting it wrongly.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
* DOC: add the changelog entry for this branch
By hand, because the automation cannot run on a pull request from a fork
(#1101).
No documented API breaks, but the observable behaviour does: an invalid string,
an empty list or a boolean trigger now fails during StochasticParachute
validation rather than later in Parachute construction, or silently becoming a
one-metre height trigger.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
---------
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>1 parent 4b187cd commit 6224be7
3 files changed
Lines changed: 150 additions & 9 deletions
File tree
- rocketpy/stochastic
- tests/unit/stochastic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
8 | 23 | | |
9 | 24 | | |
10 | 25 | | |
| |||
114 | 129 | | |
115 | 130 | | |
116 | 131 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
121 | 135 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
127 | 152 | | |
128 | 153 | | |
129 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
19 | 25 | | |
20 | 26 | | |
21 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
0 commit comments