Skip to content

Commit f45eb73

Browse files
Changed duck typing exception to: (ImportError, AttributeError) (#7874)
* Changed duck typing exception to (ImportError, AttributeError) to allow checking for missing attributes in imported packages * Updated whats-new.rst with the duck typing exception catch update of PR 7874. * Remove accidental url in whats-new * Issue number in whats-new.rst --------- Co-authored-by: Tom Nicholas <[email protected]>
1 parent 609a901 commit f45eb73

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

doc/whats-new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Internal Changes
5151
(:pull:`7847`) By `Tom Nicholas <https://github.com/TomNicholas>`_.
5252
- Xarray now uploads nightly wheels to https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/.
5353
By `Martin Fleischmann <https://github.com/martinfleis>`_.
54+
- Added an exception catch for ``AttributeError`` along with ``ImportError`` when duck typing the dynamic imports in pycompat.py. This catches some name collisions between packages. (:issue:`7870`, :pull:`7874`)
5455

5556
.. _whats-new.2023.05.0:
5657

xarray/core/pycompat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, mod: ModType) -> None:
5050
else:
5151
raise NotImplementedError
5252

53-
except ImportError: # pragma: no cover
53+
except (ImportError, AttributeError): # pragma: no cover
5454
duck_array_module = None
5555
duck_array_version = Version("0.0.0")
5656
duck_array_type = ()

0 commit comments

Comments
 (0)