Skip to content

Commit 8b8f355

Browse files
authored
Merge pull request #1076 from jvtm/python311-date-fromisoformat-allows-extra-formats
fix: Python 3.11 date.fromisoformat() allows extra formats
2 parents d09feb6 + 781f8cd commit 8b8f355

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

jsonschema/_format.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
typing.Type[Exception], typing.Tuple[typing.Type[Exception], ...],
1818
]
1919

20+
_RE_DATE = re.compile(r"^\d{4}-\d{2}-\d{2}$", re.ASCII)
21+
2022

2123
class FormatChecker:
2224
"""
@@ -396,7 +398,10 @@ def is_regex(instance: object) -> bool:
396398
def is_date(instance: object) -> bool:
397399
if not isinstance(instance, str):
398400
return True
399-
return bool(instance.isascii() and datetime.date.fromisoformat(instance))
401+
return bool(
402+
_RE_DATE.fullmatch(instance)
403+
and datetime.date.fromisoformat(instance)
404+
)
400405

401406

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

0 commit comments

Comments
 (0)