Skip to content

Commit 31b7491

Browse files
Code review fixes. Cleanup err
1 parent e518d29 commit 31b7491

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/schema_traverse.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ macro_rules! defaultdict_list_append {
3333
($dict: expr, $key: expr, $value: expr) => {{
3434
match $dict.get_item($key)? {
3535
None => {
36-
let list = PyList::empty_bound($dict.py());
37-
list.append($value)?;
36+
let list = PyList::new_bound($dict.py(), [$value]);
3837
$dict.set_item($key, list)?;
3938
}
4039
// Safety: we know that the value is a PyList as we just created it above
@@ -51,11 +50,10 @@ fn gather_definition_ref(schema_ref_dict: &Bound<'_, PyDict>, ctx: &mut GatherCt
5150
let schema_ref_str = schema_ref_pystr.to_str()?;
5251

5352
if !ctx.recursively_seen_refs.contains(schema_ref_str) {
54-
defaultdict_list_append!(&ctx.def_refs, schema_ref_pystr, schema_ref_dict);
55-
5653
let Some(definition) = ctx.definitions.get_item(schema_ref_pystr)? else {
57-
return py_err!(GatherInvalidDefinitionError; "Unknown schema_ref: {}", schema_ref_str);
54+
return py_err!(GatherInvalidDefinitionError; "{}", schema_ref_str);
5855
};
56+
defaultdict_list_append!(&ctx.def_refs, schema_ref_pystr, schema_ref_dict);
5957

6058
ctx.recursively_seen_refs.insert(schema_ref_str.to_string());
6159

tests/test_gather_schemas_for_cleaning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,5 @@ class Model:
119119
def test_unknown_ref():
120120
ref1 = core_schema.definition_reference_schema('ref1')
121121
schema = core_schema.tuple_schema([core_schema.int_schema(), ref1])
122-
with pytest.raises(GatherInvalidDefinitionError, match='Unknown schema_ref: ref1'):
122+
with pytest.raises(GatherInvalidDefinitionError, match='ref1'):
123123
gather_schemas_for_cleaning(schema, definitions={}, find_meta_with_keys=None)

0 commit comments

Comments
 (0)