-
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 dynamic default values for Union traits #1522
Conversation
if 'default_value' in metadata: | ||
default_value = metadata.pop("default_value") | ||
elif self.list_ctrait_instances: |
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.
The condition here is unnecessary: list_ctrait_instances
is always nonempty.
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.
just to be clear, this is always nonempty because we can't/don't use trait = Union()
. right?
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.
Union()
is legal, but it's equivalent to Union(None)
. That doesn't feel quite right to me (I think I'd prefer an exception), but fixing it is outside the scope of this issue. Code ref:
Lines 3982 to 3983 in 385f42b
if not traits: | |
traits = (_NoneTrait,) |
@@ -27,7 +28,7 @@ def validate(self, obj, name, value): | |||
self.error(obj, name, value) | |||
|
|||
|
|||
class TestCaseEnumTrait(unittest.TestCase): | |||
class TestUnion(unittest.TestCase): |
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 fix of long-standing copypasta.
This PR fixes the default value for a trait of the form
Union(List(Int), Str)
so that appropriate validation is performed on the list.Fixes the Union part of #1520.
Closes #1131.