Skip to content

Commit 2f1d5ef

Browse files
committed
better handling for Python 3.6
1 parent b8dd5a6 commit 2f1d5ef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

jsonschema/_format.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,12 @@ def is_regex(instance):
323323
def is_date(instance):
324324
if not isinstance(instance, str):
325325
return True
326-
try:
327-
return datetime.date.fromisoformat(instance)
328-
except AttributeError:
329-
return datetime.datetime.strptime(instance, "%Y-%m-%d")
326+
if hasattr(datetime.date, "fromisoformat"):
327+
_is_date = datetime.date.fromisoformat
328+
else:
329+
def _is_date(instance):
330+
return datetime.datetime.strptime(instance, "%Y-%m-%d")
331+
return _is_date(instance)
330332

331333

332334
@_checks_drafts(draft3="time", raises=ValueError)

0 commit comments

Comments
 (0)