| 234 | |
| 235 | @attrs(repr=False, slots=True, unsafe_hash=True) |
| 236 | class _InValidator: |
| 237 | options = attrib() |
| 238 | _original_options = attrib(hash=False) |
| 239 | |
| 240 | def __call__(self, inst, attr, value): |
| 241 | try: |
| 242 | in_options = value in self.options |
| 243 | except TypeError: class="cm"># e.g. `1 in class="st">"abc"` |
| 244 | in_options = False |
| 245 | |
| 246 | if not in_options: |
| 247 | msg = fclass="st">"&class="cm">#x27;{attr.name}' must be in {self._original_options!r} (got {value!r})" |
| 248 | raise ValueError( |
| 249 | msg, |
| 250 | attr, |
| 251 | self._original_options, |
| 252 | value, |
| 253 | ) |
| 254 | |
| 255 | def __repr__(self): |
| 256 | return fclass="st">"<in_ validator with options {self._original_options!r}>" |
| 257 | |
| 258 | |
| 259 | def in_(options): |