-
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
Fix allow_none to work correctly on BaseInstance objects #1433
Conversation
Note: while this is a bugfix, it's a long-standing bug that hasn't caused major issues, so it doesn't seem worth backporting to any bugfix release on the 6.2.x branch. |
@@ -281,6 +281,11 @@ def clone(self, default_value=NoDefaultSpecified, **metadata): | |||
A dictionary of metadata names and corresponding values as | |||
arbitrary keyword arguments. | |||
|
|||
Returns |
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.
Drive-by documentation fix; no associated change in behaviour.
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 with one question - I'm not sure why this fix only works on BaseInstance
objects and not on BaseInstance
subclasses? Won't the subclasses inherit the behavior via the inherited clone
method?
It works on both. I'll fix the title to be less misleading. (The point of the title is that the usual pattern is |
To be clear: before this PR
This PR fixes the second part above. |
Currently instances of
BaseInstance
don't clone themselves correctly when called with a new version ofallow_none
. This means thatTime(allow_none=False)
andDatetime(allow_none=False)
don't work as expected:Example (on the master branch):
This PR fixes the issue by extending the base class
clone
method to add special handling ofallow_none
. With the PR, the above example becomes:We also take the opportunity to add some basic tests for the
Datetime
andTime
trait types.Fixes #495
Checklist
[ ] Update API reference (N/Adocs/source/traits_api_reference
)[ ] Update User manual (N/Adocs/source/traits_user_manual
)[ ] Update type annotation hints inN/Atraits-stubs