Skip to content

Commit

Permalink
chore: fix type hints and docs in settingsfield
Browse files Browse the repository at this point in the history
  • Loading branch information
martastain committed Aug 23, 2024
1 parent 3fb3dde commit cd7354a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion ayon_server/settings/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ async def postprocess_settings_schema( # noqa
"placeholder",
"required_items",
"conditional_enum",
"conditionalEnum",
):
if extra_field := field.field_info.extra.get(extra_field_name):
if camelize(extra_field_name) not in prop:
Expand Down
19 changes: 14 additions & 5 deletions ayon_server/settings/settings_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,27 @@ def SettingsField(
tags: list[str] | None = None,
scope: list[str] | None = None,
placeholder: str | None = None,
conditional_enum: dict[str, list[str]] | None = None,
conditional_enum: bool = False,
disabled: bool = False,
# compatibility
conditionalEnum: dict[str, list[str]] | None = None, # backward compatibility
conditionalEnum: bool = False, # backward compatibility
examples: list[Any] | None = None,
# everything else
**kwargs: Any,
) -> Any:
# sanity checks

# conditionalEnum (camelCase) is deprecated, but used heavily.
# We will need to support it for a long time, but it won't hurt.
conditional_enum = conditional_enum or conditionalEnum

if kwargs:
logging.debug(f"SettingsField: unsupported argument: {kwargs}")

# Pydantic 1 uses `example` while Pydantic 2 uses `examples`
# We will support both, but before Pydantic 2 is used, `examples` will
# just use the first example. No one provides multiple examples anyway.

examples = examples or []
if example is not None:
examples.append(example)
Expand All @@ -70,8 +77,10 @@ def SettingsField(

extra: dict[str, Any] = {}

if example is not None:
extra["example"] = example
if examples and isinstance(examples, list):
extra["example"] = example[0]
# in pydantic 2, use:
# extra["examples"] = examples
if enum_resolver is not None:
extra["enum_resolver"] = enum_resolver
if required_items is not None:
Expand All @@ -86,7 +95,7 @@ def SettingsField(
extra["tags"] = tags
if placeholder is not None:
extra["placeholder"] = placeholder
if conditional_enum is not None:
if conditional_enum:
extra["conditional_enum"] = conditional_enum
if scope is not None:
extra["scope"] = scope
Expand Down

0 comments on commit cd7354a

Please sign in to comment.