-
Notifications
You must be signed in to change notification settings - Fork 85
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
Allow mutable values in Constant trait, add tests #929
Allow mutable values in Constant trait, add tests #929
Conversation
@midhun-pm: We should have a documentation update as part of this PR, too. The minimum would be updating the docstring for the |
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.
We should update the documentation as part of this PR.
Actually, the current docstring for |
Updated the docstring but didn't find any place in the mentions anything about the value accepted by |
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.
Looking good; agreed that there isn't anywhere obvious in the user docs that needs updating.
A few more suggested changes, and then I think this is good to merge.
traits/tests/test_constant.py
Outdated
class TestClass(HasTraits): | ||
c_atr = Constant(5) | ||
|
||
self.assertEqual(5, TestClass().c_atr) |
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.
Nitpick, but let's switch the order of arguments on all these self.assertEqual
calls: the usual order in Python-land is self.assertEqual(actual, expected)
rather than self.assertEqual(expected, actual)
.
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 thought it was the other way around, because when I have :
self.assertEqual(4, TestClass().c_atr)
I get the following error message (in PyCharm).
FAILED (failures=1)
5 != 4
Expected :4
Actual :5
<Click to see difference>
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.
Hmm; interesting. It's not clear cut, and some languages make other decisions, but for Traits, let's be consistent with the existing code and with core Python style (and the examples in the unittest documentation) and use (actual, expected). It makes code harder to read if we use a mix of the two styles.
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.
(If you want some fun historical reading, including Guido arguing with himself, see https://mail.python.org/pipermail/python-dev/2010-December/106875.html)
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.
LGTM. I took the liberty of fixing my own nitpick about the assertEqual
argument order.
Merging when CI approves.
Codecov Report
@@ Coverage Diff @@
## master #929 +/- ##
==========================================
+ Coverage 72.90% 73.12% +0.21%
==========================================
Files 51 51
Lines 6456 6453 -3
Branches 1301 1300 -1
==========================================
+ Hits 4707 4719 +12
+ Misses 1357 1340 -17
- Partials 392 394 +2
Continue to review full report at Codecov.
|
Fixes #819
This PR removes a restriction on the
Constant
trait where theConstant
trait could not be initialized with mutable types such aslist
anddict
.