-
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
Add DefaultValue.disallow #1546
Conversation
traits/constants.py
Outdated
@@ -215,4 +219,5 @@ class DefaultValue(IntEnum): | |||
DefaultValue.callable_and_args: "factory", | |||
DefaultValue.callable: "method", | |||
DefaultValue.trait_set_object: "set", | |||
DefaultValue.unsupported: "unsupported" |
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 default_kind
property is essentially unused; I'm including this only for completeness.
There's also potential to use this in the future for |
I'm not wedded to the "unsupported" name here; alternative naming suggestions welcome. I was also considering "disallow", to match the |
Related: the Lines 110 to 111 in eb62eb6
|
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.
IIRC from the internal discussion, we decided to rename this to disallowed
instead of unsupported
.
Yes, I'll rename (but I think to "disallow" rather than "disallowed"). |
…e-type' into feature/unsupported-default-value-type
Updated for the suggested renaming; I've also edited the PR title and description to match to make it easier to find in the future. |
This PR adds a new value to the
DefaultValue
enumeration:DefaultValue.disallow
. The intent is to use this for trait types that don't have a valid default. Right now that'sEvent
andDisallow
, but it could potentially be extended to other trait types in the future. The main feature ofDefaultValue.disallow
is that an attempt to get the default value of the corresponding CTrait instance usingdefault_value_for
will fail, raisingValueError
.Rationale: With the current situation, the
Event
trait has no way to communicate that its default shouldn't be used: thedefault_value_for
method succeeds, and indicates that the default value is a constant, and that that constant valueUndefined
. That means that a trait likeTuple(Event(), Event())
has a default value of(Undefined, Undefined)
. We could potentially update the logic in traits to check forUndefined
everywhere and interpret that as "no default", but it seems cleaner to introduce a new default value type for this.This PR doesn't fix #1541, but it should enable an easy fix for that issue.
Checklist
docs/source/traits_api_reference
)[ ] Update User manual (N/Adocs/source/traits_user_manual
)traits-stubs
Update: we renamed from
DefaultValue.unsupported
toDefaultValue.disallow
; I've edited the description and title accordingly.