Skip to content

Commit f36ea19

Browse files
committed
Booleans have no anchors (when they exist at all).
1 parent 4d85229 commit f36ea19

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

referencing/jsonschema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ def _legacy_id(contents: ObjectSchema) -> URI | None:
4949

5050
def _legacy_anchor_in_id(
5151
specification: Specification[ObjectSchema],
52-
contents: ObjectSchema,
52+
contents: Schema,
5353
) -> Iterable[Anchor[ObjectSchema]]:
54+
if isinstance(contents, bool):
55+
return []
5456
id = contents.get("$id", "")
5557
if not id.startswith("#"):
5658
return []

referencing/tests/test_jsonschema.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ def test_id_of_bool(specification, value):
7979
assert specification.id_of(value) is None
8080

8181

82+
@pytest.mark.parametrize(
83+
"specification",
84+
[
85+
referencing.jsonschema.DRAFT202012,
86+
referencing.jsonschema.DRAFT201909,
87+
referencing.jsonschema.DRAFT7,
88+
referencing.jsonschema.DRAFT6,
89+
],
90+
)
91+
@pytest.mark.parametrize("value", [True, False])
92+
def test_anchors_in_bool(specification, value):
93+
assert specification.anchors_in(value) == []
94+
95+
8296
@pytest.mark.parametrize(
8397
"uri, expected",
8498
[

0 commit comments

Comments
 (0)