| 294 | |
| 295 | @attrs(repr=False, slots=True, hash=True) |
| 296 | class _InValidator(object): |
| 297 | options = attrib() |
| 298 | |
| 299 | def __call__(self, inst, attr, value): |
| 300 | try: |
| 301 | in_options = value in self.options |
| 302 | except TypeError: # e.g. `1 in "abc"` |
| 303 | in_options = False |
| 304 | |
| 305 | if not in_options: |
| 306 | raise ValueError( |
| 307 | "'{name}' must be in {options!r} (got {value!r})".format( |
| 308 | name=attr.name, options=self.options, value=value |
| 309 | ) |
| 310 | ) |
| 311 | |
| 312 | def __repr__(self): |
| 313 | return "<in_ validator with options {options!r}>".format( |
| 314 | options=self.options |
| 315 | ) |
| 316 | |
| 317 | |
| 318 | def in_(options): |