Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PropertiesList can now behave as an iterable #2345

Merged
merged 3 commits into from
Mar 26, 2024
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
8 changes: 8 additions & 0 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,14 @@ def append(self, property: Property) -> None: # noqa: A002
"""
self.wrapped[property.name] = property

def __iter__(self) -> t.Iterator[Property]:
"""Iterate all properties of the property list.

Returns:
Iterator of properties.
"""
return self.wrapped.values().__iter__()


def to_jsonschema_type(
from_type: str | sa.types.TypeEngine | type[sa.types.TypeEngine],
Expand Down
12 changes: 12 additions & 0 deletions tests/core/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,15 @@ def test_to_sql_type(jsonschema_type, expected):
def test_append_null(type_dict: dict, expected: dict):
result = append_type(type_dict, "null")
assert result == expected


def test_iterate_properties_list():
primitive_property = Property("primitive", BooleanType)
object_property = Property("object", PropertiesList(Property("value", BooleanType)))
list_property = Property("list", ArrayType(BooleanType))

properties_list = PropertiesList(primitive_property, object_property, list_property)

assert primitive_property in properties_list
assert object_property in properties_list
assert list_property in properties_list