Skip to content

Commit

Permalink
fix: ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
dblanchette committed Feb 20, 2025
1 parent 8294273 commit 003595f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,9 @@ def _to_schema(s: Any, ignore_extra_keys: bool) -> Schema:
return_schema["type"] = "string"
# JSON schema uses ECMAScript regex syntax
# Translating one to another is not easy, but this should work for simple cases
return_schema["pattern"] = re.sub(r"\(\?P<[a-z\d_]+>", "(", s.pattern_str).replace("/", r"\/")
return_schema["pattern"] = re.sub(
r"\(\?P<[a-z\d_]+>", "(", s.pattern_str
).replace("/", r"\/")
else:
if flavor != DICT:
# If not handled, do not check
Expand Down Expand Up @@ -911,7 +913,12 @@ def _default_function(nkey: Any, data: Any, error: Any) -> NoReturn:


class Literal:
def __init__(self, value: Any, description: Union[str, None] = None, title: Union[str, None] = None) -> None:
def __init__(
self,
value: Any,
description: Union[str, None] = None,
title: Union[str, None] = None,
) -> None:
self._schema: Any = value
self._description: Union[str, None] = description
self._title: Union[str, None] = title
Expand Down
9 changes: 8 additions & 1 deletion test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ def test_json_schema_regex():
"type": "object",
}


def test_json_schema_ecma_compliant_regex():
s = Schema({Optional("username"): Regex("^(?P<name>[a-zA-Z_][a-zA-Z0-9_]*)/$")})
assert s.json_schema("my-id") == {
Expand Down Expand Up @@ -1414,7 +1415,13 @@ def test_json_schema_dict_type():

def test_regex_json_schema():
s = Schema(
{Literal("productId", title="Product ID", description="The unique identifier for a product"): int},
{
Literal(
"productId",
title="Product ID",
description="The unique identifier for a product",
): int
},
name="Product",
description="A product in the catalog",
)
Expand Down

0 comments on commit 003595f

Please sign in to comment.