Skip to content

Commit

Permalink
feat: PropertiesList can now behave as an iterable (#2345)
Browse files Browse the repository at this point in the history
* Define iterable behaviour for `PropertiesList`

* Add `Returns:` to docstring

* Add test
  • Loading branch information
ReubenFrankel authored Mar 26, 2024
1 parent ca6454d commit b9622c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit b9622c7

Please sign in to comment.