Skip to content

Commit

Permalink
refactor: Make SchemaInfo effectively immutable
Browse files Browse the repository at this point in the history
This was the only instance where a modification occured after init.
The result of this is identical, simply moves the overwrite to the `dict` constructor.

#3536 (comment)
  • Loading branch information
dangotbanned committed Sep 7, 2024
1 parent 1330708 commit 230d625
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions tools/schemapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,13 @@ def to_type_repr( # noqa: C901
)
tps.update(maybe_rewrap_literal(chain.from_iterable(it_nest)))
elif isinstance(self.type, list):
options = []
subschema = SchemaInfo(dict(**self.schema))
for typ_ in self.type:
# FIXME: Rewrite this to not mutate `SchemaInfo.schema`
subschema.schema["type"] = typ_
# We always use title if possible for nested objects
options.append(
subschema.to_type_repr(target=target, use_concrete=use_concrete)
# We always use title if possible for nested objects
tps.update(
SchemaInfo(dict(self.schema, type=tp)).to_type_repr(
target=target, use_concrete=use_concrete
)
tps.update(options)
for tp in self.type
)
elif self.is_array():
tps.add(
spell_nested_sequence(self, target=target, use_concrete=use_concrete)
Expand Down

0 comments on commit 230d625

Please sign in to comment.