Skip to content

Commit

Permalink
Update the (ancient draft3) color format for newer webcolors.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Julian committed Jun 17, 2024
1 parent a1fccdc commit 7fd28c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ format-nongpl = [
"rfc3339-validator",
"rfc3986-validator>0.1.0",
"uri_template",
"webcolors>=1.11",
"webcolors>=24.6.0",
]

[project.scripts]
Expand Down

0 comments on commit 7fd28c3

Please sign in to comment.