From f5c913258c06d18811a469a9acbdc3ae247db00b Mon Sep 17 00:00:00 2001 From: "Vipul Gupta (@vipulgupta2048)" Date: Sat, 17 Aug 2019 12:20:37 +0530 Subject: [PATCH 1/2] Docs: Adds maxlength & minlength examples Signed-off-by: Vipul Gupta (@vipulgupta2048) --- AUTHORS | 1 + docs/validation-rules.rst | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index d415b110..c8b742e8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -55,6 +55,7 @@ Contributors - Sergey Leshchenko - Tobias Betz - Trong Hieu HA +- Vipul Gupta - Waldir Pimenta - calve - gilbsgilbs diff --git a/docs/validation-rules.rst b/docs/validation-rules.rst index b4e8aacc..727d1ed4 100644 --- a/docs/validation-rules.rst +++ b/docs/validation-rules.rst @@ -444,7 +444,23 @@ The assigned data can be of any type. min, max -------- -Minimum and maximum value allowed for any types that implement comparison operators. +Minimum and maximum value allowed for any types that implement comparison operators. See +`\*of-rules`_ for examples. + +.. doctest:: + + >>> schema = {'weight':{'type':'float', 'min': 10.1,'max':10.9}} + >>> document = {'weight': 10.3} + + >>> v.validate(document, schema) + True + + >>> document = {'weight': 12} + >>> v.validate(document, schema) + False + + >>> v.errors + {'weight': ['max value is 10.9']} .. versionchanged:: 1.0 Allows any type to be compared. @@ -455,7 +471,23 @@ Minimum and maximum value allowed for any types that implement comparison operat minlength, maxlength -------------------- -Minimum and maximum length allowed for iterables. +Minimum and maximum length allowed for any objects that implements __len__. Examples are as follows: + +.. doctest:: + + >>> schema = {'numbers': {'type': 'list', 'minlength': 1, 'maxlength': 3}} + >>> document = {'numbers': [256, 2048, 23]} + + >>> v.validate(document, schema) + True + + >>> document = {'numbers': [256, 2048, 23, 2]} + >>> v.validate(document, schema) + False + + >>> v.errors + {'numbers': ['max length is 3']} + noneof ------ From 78f9a14e9bae764931e70176a18742f17db68529 Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Tue, 27 Aug 2019 00:49:48 +0200 Subject: [PATCH 2/2] Polishes the previous docs update --- docs/validation-rules.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/validation-rules.rst b/docs/validation-rules.rst index 727d1ed4..41670151 100644 --- a/docs/validation-rules.rst +++ b/docs/validation-rules.rst @@ -444,14 +444,13 @@ The assigned data can be of any type. min, max -------- -Minimum and maximum value allowed for any types that implement comparison operators. See -`\*of-rules`_ for examples. +Minimum and maximum value allowed for any object whose class implements +comparison operations (``__gt__`` & ``__lt__``). .. doctest:: - >>> schema = {'weight':{'type':'float', 'min': 10.1,'max':10.9}} + >>> schema = {'weight': {'min': 10.1, 'max': 10.9}} >>> document = {'weight': 10.3} - >>> v.validate(document, schema) True @@ -471,13 +470,12 @@ Minimum and maximum value allowed for any types that implement comparison operat minlength, maxlength -------------------- -Minimum and maximum length allowed for any objects that implements __len__. Examples are as follows: +Minimum and maximum length allowed for sized types that implement ``__len__``. .. doctest:: - >>> schema = {'numbers': {'type': 'list', 'minlength': 1, 'maxlength': 3}} + >>> schema = {'numbers': {'minlength': 1, 'maxlength': 3}} >>> document = {'numbers': [256, 2048, 23]} - >>> v.validate(document, schema) True