summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHillel Arnold <helrond@hotmail.com>2020-08-19 19:02:25 -0400
committerHillel Arnold <helrond@hotmail.com>2020-08-19 19:02:25 -0400
commit2f1d5ef2767dd7f1593240b67f7afd08eae81fc6 (patch)
treedea4584663e83738bb3928f38fb8dc98e98c7401
parentb8dd5a6dc345583b09b1efaa5afc83273213fdf7 (diff)
downloadjsonschema-2f1d5ef2767dd7f1593240b67f7afd08eae81fc6.tar.gz
better handling for Python 3.6
-rw-r--r--jsonschema/_format.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/jsonschema/_format.py b/jsonschema/_format.py
index 202c950..ba324ca 100644
--- a/jsonschema/_format.py
+++ b/jsonschema/_format.py
@@ -323,10 +323,12 @@ def is_regex(instance):
def is_date(instance):
if not isinstance(instance, str):
return True
- try:
- return datetime.date.fromisoformat(instance)
- except AttributeError:
- return datetime.datetime.strptime(instance, "%Y-%m-%d")
+ if hasattr(datetime.date, "fromisoformat"):
+ _is_date = datetime.date.fromisoformat
+ else:
+ def _is_date(instance):
+ return datetime.datetime.strptime(instance, "%Y-%m-%d")
+ return _is_date(instance)
@_checks_drafts(draft3="time", raises=ValueError)