From a0b6b241a05b825077decccdf99af43eab35ab34 Mon Sep 17 00:00:00 2001 From: Libor Date: Wed, 17 Jul 2024 07:43:03 +0200 Subject: [PATCH] Rework example of or_ validator in api/docs.rst --- docs/api.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 5946ab657..36520b5a1 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -466,18 +466,23 @@ All objects from ``attrs.validators`` are also available from ``attr.validators` .. doctest:: - >>> from typing import Union + >>> from typing import List, Union >>> @define ... class C: - ... val: Union[int, str] = field(validator=attrs.validators.or_(attrs.validators.instance_of(int), attrs.validators.instance_of(str))) + ... val: Union[int, List[int]] = field( + ... validator=attrs.validators.or_( + ... attrs.validators.instance_of(int), + ... attrs.validators.deep_iterable(attrs.validators.instance_of(int)), + ... ) + ... ) >>> C(42) C(val=42) - >>> C("42") - C(val='42') - >>> C(3.14) + >>> C([1, 2, 3]) + C(val=[1, 2, 3]) + >>> C(val='42') Traceback (most recent call last): ... - ValueError: None of (>, >) satisfied for value 3.14 + ValueError: None of (>, >>) satisfied for value '42' .. autofunction:: attrs.validators.not_