Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent warning repeats #5506

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix warnings
  • Loading branch information
stephenworsley committed Feb 11, 2024
commit 730eb38579029007c87193b97858ac41886f61ef
8 changes: 4 additions & 4 deletions lib/iris/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@ class IrisSaverFillValueWarning(IrisMaskValueMatchWarning, IrisSaveWarning):


@lru_cache(None)
def warn_once(msg, type, stacklevel, frame):
def warn_once(msg, type, stacklevel, frame, **kwargs):
"""Raise a warning only if a similar one has not been raised before."""
warnings.warn(msg, type, stacklevel=stacklevel)
warnings.warn(msg, type, stacklevel=stacklevel, **kwargs)


def warn_once_at_level(msg, type=None, stacklevel=0):
def warn_once_at_level(msg, type=None, stacklevel=0, **kwargs):
"""
Raise a warning only if a similar one hasn't been raised from the same line
for a given stack level.
"""
stacklevel += 1
frame = traceback.format_stack()[-stacklevel]
warn_once(msg, type, stacklevel + 1, frame)
warn_once(msg, type, stacklevel + 1, frame, **kwargs)