Commit 93eaf6d
committed
Fix uses of PyObject_IsTrue.
PyObject_IsTrue can return -1 if an exception occurred when trying to
convert a Python object to a bool (a typical case is for numpy arrays,
which cannot be converted to bools). Failure to handle this correctly
results e.g. in
```
l, = plt.plot([1, 2]); l.get_path().should_simplify = np.array([1, 2])
```
```
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 501, in _draw_idle
<elided>
File "/usr/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 146, in draw_path
self._renderer.draw_path(gc, path, transform, rgbFace)
SystemError: PyEval_EvalFrameEx returned a result with an error set
```
whereas after this PR, the ValueError gets correctly propagated out.
No tests, because one really needs to go out of their way to trigger the
faulty cases anyways...1 parent 666d3d0 commit 93eaf6d
2 files changed
Lines changed: 26 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
634 | | - | |
635 | | - | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
636 | 640 | | |
637 | 641 | | |
638 | 642 | | |
| |||
709 | 713 | | |
710 | 714 | | |
711 | 715 | | |
712 | | - | |
713 | | - | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
714 | 722 | | |
715 | 723 | | |
716 | 724 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
124 | 123 | | |
125 | | - | |
126 | | - | |
127 | 124 | | |
128 | 125 | | |
129 | 126 | | |
| |||
389 | 386 | | |
390 | 387 | | |
391 | 388 | | |
392 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
| |||
438 | 439 | | |
439 | 440 | | |
440 | 441 | | |
441 | | - | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
445 | | - | |
446 | 444 | | |
447 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
448 | 450 | | |
449 | | - | |
450 | 451 | | |
451 | 452 | | |
452 | 453 | | |
| |||
0 commit comments