Skip to content

Commit

Permalink
fix: use a higher stacklevel on warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarolopez committed Jun 7, 2024
1 parent f89bc71 commit 8f3362d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deepaas/api/v2/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def setup_debug():
"restriction in the /debug/ endpoint. Disable it whenever "
"you have finished debugging your application. \033[0m"
)
warnings.warn(msg, RuntimeWarning)
warnings.warn(msg, RuntimeWarning, stacklevel=2)

sys.stdout = MultiOut(DEBUG_STREAM, sys.stdout)
sys.stderr = MultiOut(DEBUG_STREAM, sys.stderr)
Expand Down
5 changes: 3 additions & 2 deletions deepaas/model/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def register_models(app):
warnings.warn(
"Error loading models, using test model. This will be deprecated soon.",
DeprecationWarning,
stacklevel=2,
)

if MODELS:
if len(MODELS) > 1:
# Loading several models will be deprecated in the future
warn_msg = "Loading several models is deprecated."
warnings.warn(warn_msg, DeprecationWarning)
warnings.warn(warn_msg, DeprecationWarning, stacklevel=2)
LOG.warning(warn_msg)

MODELS_LOADED = True
Expand All @@ -79,7 +80,7 @@ def register_models(app):
"API, please use the demo_app instead. "
"Check https://github.com/deephdc/demo_app for more information.",
)
warnings.warn(warn_msg, DeprecationWarning)
warnings.warn(warn_msg, DeprecationWarning, stacklevel=2)
LOG.info("No models found in V2, loading test model")
LOG.warning(warn_msg)
MODELS["deepaas-test"] = wrapper.ModelWrapper(
Expand Down

0 comments on commit 8f3362d

Please sign in to comment.