Skip to content

Commit

Permalink
refactor: Un-special-case Dict, include in SchemaInfo.is_type_alias
Browse files Browse the repository at this point in the history
The schema here is unique and aligns (conceptually) with the excluded types that fell under this rule
  • Loading branch information
dangotbanned committed Sep 9, 2024
1 parent 0af1cd1 commit 2670e3b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/schemapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def title_to_type_reprs(self, *, use_concrete: bool) -> set[str]:
# try to check for the type of the Parameter.param attribute
# but then we would need to write some overload signatures for
# api.param).
EXCLUDE_TITLE: set[str] = tp_param | {"Dict", "RelativeBandSize"}
EXCLUDE_TITLE: set[str] = tp_param | {"RelativeBandSize"}
"""
`RelativeBandSize` excluded as it has a single property `band`,
but all instances also accept `float`.
Expand Down Expand Up @@ -743,7 +743,7 @@ def is_type_alias(self) -> bool:
"""
Represents a name assigned to a literal type.
At the time of writing, all of these are:
At the time of writing, most of these are:
SchemaInfo.schema = {"type": "string"}
Expand All @@ -757,10 +757,19 @@ def is_type_alias(self) -> bool:
arg = FieldName("name 1")
The latter is not useful and adds noise.
``Dict`` is very similar case, with a *slightly* different schema:
SchemaInfo.schema = {"additionalProperties": {}, "type": "object"}
"""
TP = "type"
ADDITIONAL = "additionalProperties"
keys = self.schema.keys()
return (
self.schema.keys() == {TP}
(
(keys == {TP})
or (keys == {TP, ADDITIONAL} and self.schema[ADDITIONAL] == {})
)
and isinstance(self.type, str)
and self.type in jsonschema_to_python_types
)
Expand Down

0 comments on commit 2670e3b

Please sign in to comment.