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
Add a DeprecationWarning for when edit is false in configure_traits() #1272
Conversation
Hi @avats-dev Thank you for this! I think the CI is unhappy about building the documentation, i.e. this line fails: Line 54 in 91cd08c
The error message is the following:
The last successful build was using Sphinx 3.1.2. The CI build for this PR is using Sphinx 3.2.0. Back to the deprecation on I think the intended outcome of this deprecation is that no one should be calling e.g.
But there should be deprecation warning for this:
And deprecation warning for this:
I think in this PR, we get deprecation warning for this:
but not for this:
I think we want to emit deprecation even when So we are almost there, but not quite yet. Could you modify this PR please? |
Confirmed this is an issue for master too. I opened #1273. |
Thanks @kitchoi for the analysis and review. I think you're right about the deprecation warning if
|
I'd probably change the default value of |
That said, this won't catch the situation where someone calls
Looks like |
Ok, I also thought that it might be an overkill here, and so I think I'll just go with the |
Hi @avats-dev! Do you think you'll have time to finish this one off? Don't worry if not - just let us know, and we'll pick it up from here. |
@mdickinson I got busy with something else so I couldn't complete this. I'll finish this soon. 🚀 |
Updated 🎉 |
The Appveyor failure is a known issue that's independent of this PR, and should be fixed by #1290. |
traits/has_traits.py
Outdated
@@ -2034,7 +2037,7 @@ def configure_traits( | |||
with open(filename, "rb") as fd: | |||
self.copy_traits(pickle.Unpickler(fd).load()) | |||
|
|||
if edit: | |||
if edit is None: |
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 we can refactor this a bit to remove duplication: the goal would be to not have the same logic expressed in different branches. (Read up on the "DRY Principle" for some of the rationale for avoiding duplication.)
If you do something like:
if edit is None:
edit = True
else:
warnings.warn(...)
here, then you should be able to leave the rest of the code unchanged.
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.
But as we're showing warning for both edit=True
and edit=False
, then refactoring like
if edit is None:
edit = True
else:
warnings.warn(...)
would give warning even on None, but we don't want that.
I've added spaces as mentioned and refactored code. See if it's good?
Sorry for being late. I was out of station for some days so I was not able to work on this.
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.
would give warning even on None
I don't see how. If edit
is None
, then the first branch of the if
statement is taken, and no warning is given. If edit
is not None
, then the else
branch is taken, and a warning is given. I think that exactly matches what we want, doesn't it?
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 for the new commits! There's a fix needed for the deprecation notes in the documentation, and a suggested reworking to remove some of the duplication.
The logic still isn't right here; luckily, the tests are failing, which is exactly what they're designed to do (yay!). Can you dig into the test failures and figure out what's wrong? I also highly recommend running the tests yourself locally while you're developing, in addition to the manual testing. You can run just the relevant tests with:
Here's what I currently see on my machine when I run those tests:
What we want to see here is no test failures, and no unsuppressed warnings. |
@avats-dev I opened a PR against your branch (avats-dev#1). That PR doesn't change the main logic, it just adds one test and expands the other two a bit, so that we have good test code to work against when validating the logic in the main function. (By the way, if you're interested in this approach to development, I recommend reading up on Test Driven Development.) |
Augment and strengthen tests for deprecation of edit parameter
@mdickinson , Why tests are passing on |
Probably because these tests aren't running on Python 3.9: we don't set up the GUI system on Python 3.9, since there are issues with the PySide2 back end. If you look at the detailed test run results on Python 3.9, you'll see that the tests in this PR are skipped:
|
@avats-dev It would be great to get this finished up and merged. Is there anything I can help with? |
@avats-dev I made a new PR (#1311) that builds on your commits to fix this issue. Thank you for your contributions here! |
@mdickinson sorry I couldn't complete this. Will contribute more when I'm free. Thanks for the PR. |
@avats-dev No problem; thank you for the contribution! Note that my PR built on yours, so your commits did go into the master branch - you're now officially a Traits contributor. |
fixes #1271
Checklist
docs/source/traits_api_reference
)docs/source/traits_user_manual
)traits-stubs