Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AlexWaygood opened this issue Jun 9, 2024 · 2 comments

Comments

@AlexWaygood
Copy link

AlexWaygood commented Jun 9, 2024

(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.

@Julian
Copy link
Member

Julian commented Jun 10, 2024

Thanks! Indeed good to know, will have a look. Appreciated!

Julian added a commit that referenced this issue Jun 17, 2024
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
@Julian
Copy link
Member

Julian commented Jun 17, 2024

Should be fixed in the next release, thanks again.

@Julian Julian closed this as completed Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants