{"action":"created","issue":{"url":"https://api.github.com/repos/ipython/traitlets/issues/335","repository_url":"https://api.github.com/repos/ipython/traitlets","labels_url":"https://api.github.com/repos/ipython/traitlets/issues/335/labels{/name}","comments_url":"https://api.github.com/repos/ipython/traitlets/issues/335/comments","events_url":"https://api.github.com/repos/ipython/traitlets/issues/335/events","html_url":"https://github.com/ipython/traitlets/pull/335","id":184726394,"number":335,"title":"Add Chained Validators","user":{"login":"rmorshea","id":4041990,"avatar_url":"https://avatars.githubusercontent.com/u/4041990?v=3","gravatar_id":"","url":"https://api.github.com/users/rmorshea","html_url":"https://github.com/rmorshea","followers_url":"https://api.github.com/users/rmorshea/followers","following_url":"https://api.github.com/users/rmorshea/following{/other_user}","gists_url":"https://api.github.com/users/rmorshea/gists{/gist_id}","starred_url":"https://api.github.com/users/rmorshea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmorshea/subscriptions","organizations_url":"https://api.github.com/users/rmorshea/orgs","repos_url":"https://api.github.com/users/rmorshea/repos","events_url":"https://api.github.com/users/rmorshea/events{/privacy}","received_events_url":"https://api.github.com/users/rmorshea/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2016-10-24T00:16:09Z","updated_at":"2016-11-24T13:39:25Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ipython/traitlets/pulls/335","html_url":"https://github.com/ipython/traitlets/pull/335","diff_url":"https://github.com/ipython/traitlets/pull/335.diff","patch_url":"https://github.com/ipython/traitlets/pull/335.patch"},"body":"Closes #298\r\n\r\nAllows for validator functions via arguments and simple attribute validation via keywords.\r\n\r\n``` python\r\nclass Z(object):\r\n    def __init__(self, x, y):\r\n        self.x, self.y = x, y\r\n\r\ndef valid_x(trait, value):\r\n    if value.x != 1:\r\n        raise TraitError(\"'x' must be 1\")\r\n    return value\r\n\r\nclass A(HasTraits):\r\n    b = TraitType().allows(valid_x, y=1)\r\n\r\na = A()\r\na.b = Z(1, 1) # pass\r\na.b = Z(0, 1) # raise\r\na.b = Z(1, 0) # raise\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/ipython/traitlets/issues/comments/262778375","html_url":"https://github.com/ipython/traitlets/pull/335#issuecomment-262778375","issue_url":"https://api.github.com/repos/ipython/traitlets/issues/335","id":262778375,"user":{"login":"minrk","id":151929,"avatar_url":"https://avatars.githubusercontent.com/u/151929?v=3","gravatar_id":"","url":"https://api.github.com/users/minrk","html_url":"https://github.com/minrk","followers_url":"https://api.github.com/users/minrk/followers","following_url":"https://api.github.com/users/minrk/following{/other_user}","gists_url":"https://api.github.com/users/minrk/gists{/gist_id}","starred_url":"https://api.github.com/users/minrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minrk/subscriptions","organizations_url":"https://api.github.com/users/minrk/orgs","repos_url":"https://api.github.com/users/minrk/repos","events_url":"https://api.github.com/users/minrk/events{/privacy}","received_events_url":"https://api.github.com/users/minrk/received_events","type":"User","site_admin":false},"created_at":"2016-11-24T13:39:25Z","updated_at":"2016-11-24T13:39:25Z","body":"> Would it make it less consistent to not have the same behavior here?\r\n\r\nYes, absolutely. I think the question is about whether we want to separate validation from coercion moving forward, and if so it makes sense to start with new APIs (i.e. deprecate validators that coerce). I'm fine with keeping the current validation concept."}}
{"actor":{"display_login":"minrk"}}