Status
Confirmed on 2026-09-13 against origin/main 0266d08. Found while testing #149: a test that turns all warnings into errors failed when it built a sync client.
Defect
OilPriceAPI.__init__ (oilpriceapi/client.py:224-230) always constructs PriceVisualizer(self). PriceVisualizer.__init__ (oilpriceapi/visualization.py:92-97) calls warnings.warn("matplotlib is required for visualization. Install with: pip install matplotlib", ImportWarning) whenever matplotlib is not installed.
So every sync client built without the optional matplotlib extra warns about a feature the caller has not used.
- Python's default filters ignore
ImportWarning, so plain scripts do not show it.
- Anything that surfaces warnings does show it: pytest's warning summary,
-W error, and warnings.simplefilter("error"/"always").
- Under
-W error or simplefilter("error"), client construction raises.
The except ImportError around the construction does not catch it, because a warning is not an ImportError.
Repro
import warnings
from oilpriceapi import OilPriceAPI
with warnings.catch_warnings():
warnings.simplefilter("error")
OilPriceAPI(api_key="-".join(["fixture", "not", "a", "real", "key"]))
# ImportWarning: matplotlib is required for visualization. Install with: pip install matplotlib
Run in an environment with the SDK installed and matplotlib absent.
Expected
Construction emits nothing. Warn, or raise an error that names the extra, only when a client.viz plotting method is actually called without matplotlib.
Status
Confirmed on 2026-09-13 against
origin/main0266d08. Found while testing #149: a test that turns all warnings into errors failed when it built a sync client.Defect
OilPriceAPI.__init__(oilpriceapi/client.py:224-230) always constructsPriceVisualizer(self).PriceVisualizer.__init__(oilpriceapi/visualization.py:92-97) callswarnings.warn("matplotlib is required for visualization. Install with: pip install matplotlib", ImportWarning)whenever matplotlib is not installed.So every sync client built without the optional
matplotlibextra warns about a feature the caller has not used.ImportWarning, so plain scripts do not show it.-W error, andwarnings.simplefilter("error"/"always").-W errororsimplefilter("error"), client construction raises.The
except ImportErroraround the construction does not catch it, because a warning is not an ImportError.Repro
Run in an environment with the SDK installed and matplotlib absent.
Expected
Construction emits nothing. Warn, or raise an error that names the extra, only when a
client.vizplotting method is actually called without matplotlib.