{"action":"created","issue":{"url":"https://api.github.com/repos/enthought/traits/issues/402","repository_url":"https://api.github.com/repos/enthought/traits","labels_url":"https://api.github.com/repos/enthought/traits/issues/402/labels{/name}","comments_url":"https://api.github.com/repos/enthought/traits/issues/402/comments","events_url":"https://api.github.com/repos/enthought/traits/issues/402/events","html_url":"https://github.com/enthought/traits/issues/402","id":335858766,"node_id":"MDU6SXNzdWUzMzU4NTg3NjY=","number":402,"title":"Proposal: The Undefined singleton should by falsey","user":{"login":"tmreay","id":37627669,"node_id":"MDQ6VXNlcjM3NjI3NjY5","avatar_url":"https://avatars1.githubusercontent.com/u/37627669?v=4","gravatar_id":"","url":"https://api.github.com/users/tmreay","html_url":"https://github.com/tmreay","followers_url":"https://api.github.com/users/tmreay/followers","following_url":"https://api.github.com/users/tmreay/following{/other_user}","gists_url":"https://api.github.com/users/tmreay/gists{/gist_id}","starred_url":"https://api.github.com/users/tmreay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmreay/subscriptions","organizations_url":"https://api.github.com/users/tmreay/orgs","repos_url":"https://api.github.com/users/tmreay/repos","events_url":"https://api.github.com/users/tmreay/events{/privacy}","received_events_url":"https://api.github.com/users/tmreay/received_events","type":"User","site_admin":false},"labels":[{"id":192267967,"node_id":"MDU6TGFiZWwxOTIyNjc5Njc=","url":"https://api.github.com/repos/enthought/traits/labels/discussion","name":"discussion","color":"fbca04","default":false},{"id":314299399,"node_id":"MDU6TGFiZWwzMTQyOTkzOTk=","url":"https://api.github.com/repos/enthought/traits/labels/easy","name":"easy","color":"009800","default":false},{"id":76537,"node_id":"MDU6TGFiZWw3NjUzNw==","url":"https://api.github.com/repos/enthought/traits/labels/enhancements","name":"enhancements","color":"02d7e1","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-26T14:52:48Z","updated_at":"2018-06-26T17:21:48Z","closed_at":null,"author_association":"NONE","body":"I noticed some unintuitive behavior while working on a `HasTraits` object with a `ReadOnly` attribute.\r\n\r\nI expected the default value, the `Undefined` singleton, to be falsey, but it is not. See below:\r\n\r\n```python\r\nIn [1]: from traits.api import ReadOnly, HasTraits\r\n\r\nIn [2]: class A(HasTraits):\r\n   ...:     val = ReadOnly\r\n   ...:\r\n\r\nIn [3]: a = A()\r\n\r\nIn [4]: if a.val:\r\n   ...:     print('{} evaluates to True, so lets operate on it'.format(a.val))\r\n   ...: else:\r\n   ...:     print('{} evaluates to False, so lets assign it'.format(a.val))\r\n   ...:\r\n<undefined> evaluates to True, so lets operate on it\r\n```\r\n\r\nTo properly check if the value is set, I need to import `Undefined` and then do `if a.val is Undefined`, which isn't terrible, but I'd like the option to just treat it as a `bool`.\r\n\r\nI think all that's needed is to define a `__nonzero__` method (and `__bool__` for python 3) that returns `False`\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/enthought/traits/issues/comments/400395859","html_url":"https://github.com/enthought/traits/issues/402#issuecomment-400395859","issue_url":"https://api.github.com/repos/enthought/traits/issues/402","id":400395859,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMDM5NTg1OQ==","user":{"login":"tmreay","id":37627669,"node_id":"MDQ6VXNlcjM3NjI3NjY5","avatar_url":"https://avatars1.githubusercontent.com/u/37627669?v=4","gravatar_id":"","url":"https://api.github.com/users/tmreay","html_url":"https://github.com/tmreay","followers_url":"https://api.github.com/users/tmreay/followers","following_url":"https://api.github.com/users/tmreay/following{/other_user}","gists_url":"https://api.github.com/users/tmreay/gists{/gist_id}","starred_url":"https://api.github.com/users/tmreay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmreay/subscriptions","organizations_url":"https://api.github.com/users/tmreay/orgs","repos_url":"https://api.github.com/users/tmreay/repos","events_url":"https://api.github.com/users/tmreay/events{/privacy}","received_events_url":"https://api.github.com/users/tmreay/received_events","type":"User","site_admin":false},"created_at":"2018-06-26T17:21:48Z","updated_at":"2018-06-26T17:21:48Z","author_association":"NONE","body":"To @itziakos's point, I agree that `Undefined` translating to true is the underlying bug. I view it as conceptually similar to `None`, which is why I'd prefer it to evaluate to false, but I would be fine with instead raising an error if the user tries to coerce it's value to a `bool`.\r\n\r\n@corranwebster \r\nTheres no reason the `is` check would not work, I was just wanting to avoid an extra import. In my use case, the value that would be assigned to this trait would always be truthy, so there would not be any ambiguity to treating it like a bool."}}
{"actor":{"display_login":"tmreay"}}