-
-
Notifications
You must be signed in to change notification settings - Fork 19
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 "none" values for Choices when included in constants and/or string is an allowable type #6
Conversation
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'm not convinced this is the right approach. We need to be very clear about the distinction between None
(the Python symbolic value), "none"
(a Python string with the value of "none") and NONE
(a Python constant with the value of "none").
The current code (and tests) are a bit loose, and lean towards coercing "none"
to None
; I'd argue that's the original mistake. We shouldn't be allowing None
at all.
Pack does this the right way - defining a constant NONE
- but then gets caught in the loose coercion. That is the underlying problem that needs to be fixed, AFAICT.
@@ -271,7 +272,7 @@ def __init__(self): | |||
except ValueError as v: | |||
self.assertEqual( | |||
str(v), | |||
"Invalid value 'invalid' for property 'prop'; Valid values are: a, b, none" | |||
"Invalid value 'invalid' for property 'prop'; Valid values are: a, b, none, 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.
This makes me very skeptical. Why would we want to allow both 'none' as a string value, and None as a symbolic constant, rendered as a string indistinguishable from the string form?
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.
This is a side effect of what you're calling the "original mistake." When making the proposed change, the ValueError's message also coerces Python None
to the string 'none'
. So, since we are allowing both None
and 'none'
as values in the proposed change, this is what the message ends up looking like (repeating 'none'
twice).
I agree with you about the underlying problem. Coercing |
I did some more research on this. If we need to distinguish between Python's
evaluate to If we need a workaround, I think a magic
when setting up the constant, then
but so that could be useful. Magic can be bad, but if we need this functionality, this workaround might be worth it. I've confirmed this approach works on versions 2.7 and 3.6. |
So, we will need to differentiate the symbolic |
Good. No need for magic! So where do we go to get to the root of this? |
Closed in favour of #33. |
This is a more robust approach to resolving #3.
What I'm proposing and showing here is that, instead of converting
'none'
toNone
objects and then testing that that has been done in multiple unit tests, we can just reject'none'
as a value in the appropriate cases within thevalidate
method, in one place.This passes all unit tests.