Skip to content

Commit 9acfb5b

Browse files
committed
improve note around except Exception for future devs
1 parent 8ad4d1e commit 9acfb5b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/cbook.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,9 @@ def _is_torch_array(x):
23502350
# we're intentionally not attempting to import torch. If somebody
23512351
# has created a torch array, torch should already be in sys.modules
23522352
return isinstance(x, sys.modules['torch'].Tensor)
2353-
except Exception:
2353+
except Exception: # TypeError, KeyError, AttributeError, maybe others?
2354+
# we're attempting to access attributes on imported modules which
2355+
# may have arbitrary user code, so we deliberately catch all exceptions
23542356
return False
23552357

23562358

@@ -2360,7 +2362,9 @@ def _is_jax_array(x):
23602362
# we're intentionally not attempting to import jax. If somebody
23612363
# has created a jax array, jax should already be in sys.modules
23622364
return isinstance(x, sys.modules['jax'].Array)
2363-
except Exception:
2365+
except Exception: # TypeError, KeyError, AttributeError, maybe others?
2366+
# we're attempting to access attributes on imported modules which
2367+
# may have arbitrary user code, so we deliberately catch all exceptions
23642368
return False
23652369

23662370

0 commit comments

Comments
 (0)