Commit b8945dc
committed
Reject sequences nested in a sequence of a different type in approx
ApproxSequenceLike guarded against nesting with isinstance(x, type(expected)),
which only caught an element of the same type as the container. A tuple inside a
list, or a list inside a tuple, passed the guard and was handed to ApproxScalar,
where it was compared exactly instead of approximately. That returned a wrong
bool rather than raising, so [(1.20000000000001,)] == approx([(1.2,)]) was False
while the flat (1.20000000000001,) == approx((1.2,)) was True.
Use _is_sequence_like, the same predicate approx() uses to dispatch to
ApproxSequenceLike, so nesting is rejected consistently. Mappings are excluded
so that a dict nested in a sequence keeps its current behaviour.
Closes #119451 parent 0d6fbde commit b8945dc
3 files changed
Lines changed: 31 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
362 | 369 | | |
363 | 370 | | |
364 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
924 | 924 | | |
925 | 925 | | |
926 | 926 | | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
927 | 932 | | |
928 | 933 | | |
929 | 934 | | |
| |||
933 | 938 | | |
934 | 939 | | |
935 | 940 | | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
936 | 955 | | |
937 | 956 | | |
938 | 957 | | |
| |||
0 commit comments