diff options
author | Hillel Arnold <helrond@hotmail.com> | 2020-08-19 19:02:25 -0400 |
---|---|---|
committer | Hillel Arnold <helrond@hotmail.com> | 2020-08-19 19:02:25 -0400 |
commit | 2f1d5ef2767dd7f1593240b67f7afd08eae81fc6 (patch) | |
tree | dea4584663e83738bb3928f38fb8dc98e98c7401 | |
parent | b8dd5a6dc345583b09b1efaa5afc83273213fdf7 (diff) | |
download | jsonschema-2f1d5ef2767dd7f1593240b67f7afd08eae81fc6.tar.gz |
better handling for Python 3.6
-rw-r--r-- | jsonschema/_format.py | 10 |
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) |