Skip to content

Commit 7fd28c3

Browse files
committed
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
1 parent a1fccdc commit 7fd28c3

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

jsonschema/_format.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,16 @@ def is_draft3_time(instance: object) -> bool:
413413

414414

415415
with suppress(ImportError):
416-
from webcolors import CSS21_NAMES_TO_HEX
417416
import webcolors
418417

419-
def is_css_color_code(instance: object) -> bool:
420-
return webcolors.normalize_hex(instance)
421-
422418
@_checks_drafts(draft3="color", raises=(ValueError, TypeError))
423419
def is_css21_color(instance: object) -> bool:
424-
if (
425-
not isinstance(instance, str)
426-
or instance.lower() in CSS21_NAMES_TO_HEX
427-
):
428-
return True
429-
return is_css_color_code(instance)
420+
if isinstance(instance, str):
421+
try:
422+
webcolors.name_to_hex(instance)
423+
except ValueError:
424+
webcolors.normalize_hex(instance.lower())
425+
return True
430426

431427

432428
with suppress(ImportError):

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ format-nongpl = [
6666
"rfc3339-validator",
6767
"rfc3986-validator>0.1.0",
6868
"uri_template",
69-
"webcolors>=1.11",
69+
"webcolors>=24.6.0",
7070
]
7171

7272
[project.scripts]

0 commit comments

Comments
 (0)