Skip to content

Commit 9fe1b32

Browse files
committed
fix(new.py): Directly raise an ImportError if new.py is attempted to be imported by a user without multidict being installed.
1 parent 87bf177 commit 9fe1b32

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

HISTORY.rst

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ and the release date, in year-month-day format (see examples below).
3030
Unreleased
3131
----------
3232

33+
Fixed
34+
+++++
35+
* Attempting to import pvl/new.py without multidict being available,
36+
will now properly yield an ImportError.
37+
3338
1.2.0 (2021-03-27)
3439
------------------
3540

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ lint:
4646
test:
4747
python -m pytest --doctest-modules --doctest-glob='*.rst'
4848

49+
test-min:
50+
python -m pytest --doctest-modules --ignore=pvl/new.py
51+
4952
test-all:
5053
tox
5154

pvl/new.py

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
import inspect
2727
import urllib.request
2828

29+
try: # noqa: C901
30+
# In order to access super class attributes for our derived class, we must
31+
# import the native Python version, instead of the default Cython version.
32+
from multidict._multidict_py import MultiDict
33+
except ImportError as err:
34+
raise ImportError(
35+
"The multidict library is not present, so the new PVLMultiDict is not "
36+
"available, and pvl.new can't be imported. In order to do so, install "
37+
"the multidict package",
38+
ImportWarning,
39+
) from err
40+
2941
from pvl import * # noqa: F401,F403
3042
from pvl import get_text_from, decode_by_char
3143

0 commit comments

Comments
 (0)