Skip to content

jsonschema._format.is_css_color_code and jsonschema._format.is_css21_color never exist if the latest version of webcolors is installed #1268

Closed
python/typeshed
#13215
@AlexWaygood

Description

@AlexWaygood

(This issue isn't a complaint, just an FYI!)

The following block of code will always raise ImportError if you have the latest version of webcolors installed, meaning that the contextlib.suppress block will always exit immediately, and these functions will never be defined; the block is now essentially dead code:

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)

This is because webcolors made the CSS21_NAMES_TO_HEX constant private in webcolors==24.6.0 (released on June 6), so the statement from webcolors import CSS21_NAMES_TO_HEX now always raises ImportError. The diff between the latest version of webcolors and the release before it can be seen here: ubernostrum/webcolors@1.13...24.6.0.

Obviously third parties should not be relying on any functions in the internal _format module, so this isn't a complaint! But we spotted this in typeshed's CI, and thought you might like to know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions