You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P3][bug] Constructing OilPriceAPI emits ImportWarning when matplotlib is not installed #151
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 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
importwarningsfromoilpriceapiimportOilPriceAPIwithwarnings.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.
Activity
fix: client.viz raises ImportError naming the viz extra without matpl…
fix: lazy visualizer so client construction never warns (#151); remov…
chore(deps): bump actions/download-artifact from 8.0.1 to 8.0.2 (#155)