fix: correct reversed arguments in warnings.warn call#120
Open
nishantharkut wants to merge 2 commits intoioos:mainfrom
Open
fix: correct reversed arguments in warnings.warn call#120nishantharkut wants to merge 2 commits intoioos:mainfrom
nishantharkut wants to merge 2 commits intoioos:mainfrom
Conversation
…ogy wrapper Swap the warning message and category arguments in the utils compatibility wrapper so DeprecationWarning is emitted correctly. Add stacklevel=2 so the warning points to user call sites, and add a regression test that checks warning category, message content, and caller filename.
There was a problem hiding this comment.
Pull request overview
This PR fixes a deprecated compatibility wrapper so that deprecation warnings are emitted correctly (message/category order and caller location), and adds a regression test to validate the warning behavior.
Changes:
- Fix
warnings.warncall argument order and addstacklevel=2for correct caller attribution. - Add a regression test to validate warning category, message content, and reported filename.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
xarray_subset_grid/utils.py |
Corrects warnings.warn usage in the deprecated assign_ugrid_topology wrapper and sets stacklevel=2. |
tests/test_utils.py |
Adds a focused test to assert the wrapper emits a DeprecationWarning and points at the caller location. |
Comments suppressed due to low confidence (1)
xarray_subset_grid/utils.py:108
from .grids.ugrid import assign_ugrid_topologyrebinds the local name to a different function with the same name as this deprecated wrapper. That works, but it makes stack traces/debugging confusing and is easy to misread as recursion. Consider importing with an alias (e.g.,_assign_ugrid_topology) and returning that instead.
stacklevel=2,
)
from .grids.ugrid import assign_ugrid_topology
return assign_ugrid_topology(*args, **kwargs)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xarray_subset_grid/utils.py
Outdated
Comment on lines
100
to
102
| "The function `assign_grid_topology` has been moved to the " | ||
| "`grids.ugrid` module. It will not be able to be called from " | ||
| "the utils `module` in the future.", |
xarray_subset_grid/utils.py
Outdated
| "The function `assign_grid_topology` has been moved to the " | ||
| "`grids.ugrid` module. It will not be able to be called from " | ||
| "the utils `module` in the future.", | ||
| DeprecationWarning, |
…essage Apply Copilot review suggestions: - Fix function name in warning message: change assign_grid_topology to assign_ugrid_topology (the correct function name in the repo) - Remove backticks around second occurrence of 'module' (plain English word, not code reference) - Use keyword argument category=DeprecationWarning instead of positional argument - Update test assertion to match corrected message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the deprecated compatibility wrapper so warning emission works correctly.
Problem
The warnings.warn positional arguments were reversed. That makes Python treat a string as the warning category, which raises:
TypeError: category must be a Warning subclass, not 'str'.
Changes
Validation