-
-
Notifications
You must be signed in to change notification settings - Fork 728
Introduce @deprecated decorators for functions and enforce warnings as errors in tests #4757
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Previous Discussions : #4745 (comment) |
kratman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one of the main reasons for doing this is to track the date of the deprecation warnings. This does not seem to be in these changes.
Realistically the warnings work as-is, but we want to automate the removal of them. Right now I use git-blame to remove old warnings every 6 months or so. The extra decorators and such are just additional overhead unless we use it for something better than the current warnings
|
Original issue request: "Replace existing deprecation warnings/errors with deprecation package so tests fail after a few releases." |
|
Okay , I misunderstood that the deprecation package was not required and we needed a pythonic way. I will just go ahead with the deprecation package with my next commit Apologies for the confusion |
5024850 to
ff6a817
Compare
|
@kratman, I've implemented the deprecation package for four of the existing deprecation warnings. Could you please guide me on any potential improvements? Regarding renamed and deprecated arguments, it seems the deprecation package doesn't natively handle these cases. Do you have any suggestions on how to approach this? I considered writing custom decorators to manage them. Does that sound like a good plan? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4757 +/- ##
===========================================
- Coverage 98.57% 97.65% -0.93%
===========================================
Files 304 304
Lines 23656 23672 +16
===========================================
- Hits 23320 23117 -203
- Misses 336 555 +219 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Does the package you use allow for tests to fail when the deprecation is old? |
No, the deprecation package does not natively support automatically failing tests when a deprecation is old |
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with the general idea here, and the @deprecated decorator looks neat. If there's no way to make the deprecated functions fail directly, that's fine – we should proceed with your suggestion in the PR description:
has added -W flag to ensure the deprecation warnings are treated as an error
I don't see this change here, but yes, please feel free to configure pytest with this, as the deprecation warnings would then be caught in the tests if they use it. Then, you can fix any pending deprecation warnings unrelated to your changes that show up in the test suite. If there are a bunch of them and they are not straightforward to fix, it is also okay to filter them using the filterwarnings configuration option and open a new issue about removing them to work on later.
See also: https://docs.pytest.org/en/stable/how-to/capture-warnings.html#controlling-warnings
Regarding deprecating a specific argument in a function, yes, adding a custom decorator for this sounds great. If you think it will require a bit of experimentation, I'm happy to help review it in a follow-up PR (you may edit the PR description to mark this PR as related to #2028, but not fixing it). Limiting the scope of this PR sounds good to me to get it in.
Thanks!
|
you can mark this PR as draft until pybtex is sorted ! Since the tests are failing as expected due to deprecation. |
|
Okay, after looking at the CI logs more closely, I'm not sure I follow, as the For the BPX tests, we should file an upstream issue about the Pydantic deprecation (or better, a PR fixing it) and ignore the warning in the filters here for the time being until it is fixed and makes it to a release. For the deprecation warnings in the tests that are coming from PyBaMM's deprecated APIs, those are the actual ones we need to resolve. Usually, we deprecate methods/arguments/etc. by adding a I hope this is clear! |
Understood very well |
|
Hey @agriyakhetarpal i fixed the tests with deprecated functions but i need help with the |
It has been currently ignored in the pytest |
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @RohitP2005! Just a few more comments to go here. Also, there's another warning in the doctests that we need to ignore, see: https://github.com/pybamm-team/PyBaMM/actions/runs/14079804552/job/39430386846?pr=4757
| def test_symbol_auxiliary_domains(self): | ||
| a = pybamm.Symbol( | ||
| "a", | ||
| domain="test", | ||
| auxiliary_domains={ | ||
| "secondary": "sec", | ||
| "tertiary": "tert", | ||
| "quaternary": "quat", | ||
| }, | ||
| ) | ||
| assert a.domain == ["test"] | ||
| assert a.secondary_domain == ["sec"] | ||
| assert a.tertiary_domain == ["tert"] | ||
| assert a.tertiary_domain == ["tert"] | ||
| assert a.quaternary_domain == ["quat"] | ||
| assert a.domains == { | ||
| "primary": ["test"], | ||
| "secondary": ["sec"], | ||
| "tertiary": ["tert"], | ||
| "quaternary": ["quat"], | ||
| } | ||
|
|
||
| a = pybamm.Symbol("a", domain=["t", "e", "s"]) | ||
| assert a.domain == ["t", "e", "s"] | ||
| with pytest.raises(TypeError): | ||
| a = pybamm.Symbol("a", domain=1) | ||
| b = pybamm.Symbol("b", domain="test sec") | ||
| with pytest.raises(pybamm.DomainError, match="All domains must be different"): | ||
| b.domains = {"primary": "test", "secondary": "test"} | ||
| with pytest.raises(pybamm.DomainError, match="All domains must be different"): | ||
| b = pybamm.Symbol( | ||
| "b", | ||
| domain="test", | ||
| auxiliary_domains={"secondary": ["test sec"], "tertiary": ["test sec"]}, | ||
| ) | ||
|
|
||
| with pytest.raises(NotImplementedError, match="auxiliary_domains"): | ||
| a.auxiliary_domains | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I know why this test was removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RohitP2005, this conversation is still relevant – as I'm not sure why the test was removed. It should be reinstated, or we need a valid reason for why it should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this conversation is still relevant – I'd like to know why we need to remove this test?
|
Hey @agriyakhetarpal this issue have been here for a while, |
|
@agriyakhetarpal I just need a little help, the test past successfully locally in my machine. is there smth i am missing because of which the CI are failing |
|
It fails on my end, could you please check if |
|
@agriyakhetarpal I just need to confirm the CI with this commit, kindly trigger the CIs. |
|
Hey @agriyakhetarpal I just bumped down the version of |
|
Yes, I'm okay with it if you can't ignore the warning in any other way. Thanks! |
|
@agriyakhetarpal i guess the PR is ready to merge, Once the PR completes the CI |
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @RohitP2005. This is inching closer to a merge now. I still have a few more comments:
| "-nauto", | ||
| "-vra", | ||
| "-ra", | ||
| "--showlocals", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conversation is still relevant, as I'm not sure why we need to include this option with this PR – is it related to the changes? It's useful, but if it doesn't need to be included for the main changes here, please consider adding it in another PR.
| "--showlocals", | ||
| "--strict-config", | ||
| "--strict-markers", | ||
| "--ignore=tests/unit/test_parameters/test_bpx.py", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than ignoring the file completely, let's skip/xfail the relevant tests in that file. As I previously mentioned: if you can't address/capture the warnings coming out of them, please open an issue in the BPX repo and link it here.
| def test_symbol_auxiliary_domains(self): | ||
| a = pybamm.Symbol( | ||
| "a", | ||
| domain="test", | ||
| auxiliary_domains={ | ||
| "secondary": "sec", | ||
| "tertiary": "tert", | ||
| "quaternary": "quat", | ||
| }, | ||
| ) | ||
| assert a.domain == ["test"] | ||
| assert a.secondary_domain == ["sec"] | ||
| assert a.tertiary_domain == ["tert"] | ||
| assert a.tertiary_domain == ["tert"] | ||
| assert a.quaternary_domain == ["quat"] | ||
| assert a.domains == { | ||
| "primary": ["test"], | ||
| "secondary": ["sec"], | ||
| "tertiary": ["tert"], | ||
| "quaternary": ["quat"], | ||
| } | ||
|
|
||
| a = pybamm.Symbol("a", domain=["t", "e", "s"]) | ||
| assert a.domain == ["t", "e", "s"] | ||
| with pytest.raises(TypeError): | ||
| a = pybamm.Symbol("a", domain=1) | ||
| b = pybamm.Symbol("b", domain="test sec") | ||
| with pytest.raises(pybamm.DomainError, match="All domains must be different"): | ||
| b.domains = {"primary": "test", "secondary": "test"} | ||
| with pytest.raises(pybamm.DomainError, match="All domains must be different"): | ||
| b = pybamm.Symbol( | ||
| "b", | ||
| domain="test", | ||
| auxiliary_domains={"secondary": ["test sec"], "tertiary": ["test sec"]}, | ||
| ) | ||
|
|
||
| with pytest.raises(NotImplementedError, match="auxiliary_domains"): | ||
| a.auxiliary_domains | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this conversation is still relevant – I'd like to know why we need to remove this test?
|
|
@agriyakhetarpal does the points sum up requested changes |
|
@agriyakhetarpal I have rewritten tests for auxiliary domains |
Description
This pull request has implemented deprecation decorators as wrapper for a function's arguement and the fucntion itself and has added
-Wflag to ensure the deprecation warnings are treated as errorRelated to: #2028
Type of change
Key checklist:
$ pre-commit run --all-files(or$ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally)$ python -m pytest -W error(or$ nox -s tests) (ensure warnings are treated as errors to catch deprecation notices)$ python -m pytest --doctest-plus src(or$ nox -s doctests)You can run integration tests, unit tests, and doctests together at once using
$ nox -s quick.Further checks: