Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/formbridge/forms/declared_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def _(item: DeclaredMetadata) -> Iterator[object]:
return item.declares()


@metadata_declarations.register
def documentation_declarations(item: str) -> Iterator[object]:
"""Annotation help text describes a field; it does not declare a text value."""
return iter(())


def declarations(annotation: object) -> Iterator[object]:
"""What an annotation declares, most specific first.

Expand Down
8 changes: 8 additions & 0 deletions tests/test_declared_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
assert next(iter(declarations(Annotated[str, Number()]))) is Number


@pytest.mark.parametrize("value_type", (str, int, bool))
def test_documentation_does_not_replace_the_value_or_prepared_declaration(value_type):
assert tuple(declarations(Annotated[value_type, "Field help"])) == tuple(declarations(value_type))

Check failure on line 68 in tests/test_declared_views.py

View workflow job for this annotation

GitHub Actions / code-quality

ruff (E501)

tests/test_declared_views.py:68:101: E501 Line too long (102 > 100)
annotation = Annotated[value_type, "Field help", Prepared(Count)]
assert next(declarations(annotation)) is Count
assert FieldWidget.showing(declarations(annotation)) is CountWidget


def test_a_family_asked_below_its_root_answers_from_its_own_tree():
assert NumberWidget.showing(Count.__mro__) is CountWidget
with pytest.raises(LookupError):
Expand Down
Loading