From 7fd28c3936375deb1180a45624d37c58d1576cac Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Mon, 17 Jun 2024 17:09:57 +0200 Subject: [PATCH] Update the (ancient draft3) color format for newer webcolors. Bumps the pin to the newer version, where validating these seems to now require a function call. Really we should have a better strategy in CI for ensuring we run all the format tests we intend to run, but this should happen really really rarely. Closes: ##1268 --- jsonschema/_format.py | 16 ++++++---------- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 9e4827e0..6e87620c 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -413,20 +413,16 @@ def is_draft3_time(instance: object) -> bool: with suppress(ImportError): - from webcolors import CSS21_NAMES_TO_HEX import webcolors - def is_css_color_code(instance: object) -> bool: - return webcolors.normalize_hex(instance) - @_checks_drafts(draft3="color", raises=(ValueError, TypeError)) def is_css21_color(instance: object) -> bool: - if ( - not isinstance(instance, str) - or instance.lower() in CSS21_NAMES_TO_HEX - ): - return True - return is_css_color_code(instance) + if isinstance(instance, str): + try: + webcolors.name_to_hex(instance) + except ValueError: + webcolors.normalize_hex(instance.lower()) + return True with suppress(ImportError): diff --git a/pyproject.toml b/pyproject.toml index 45dbc8c4..c4f7695c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ format-nongpl = [ "rfc3339-validator", "rfc3986-validator>0.1.0", "uri_template", - "webcolors>=1.11", + "webcolors>=24.6.0", ] [project.scripts]