From b9622c7842a2b08d0f03218ac141197d1bb20c18 Mon Sep 17 00:00:00 2001 From: ReubenFrankel <60552974+ReubenFrankel@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:09:14 +0000 Subject: [PATCH] feat: `PropertiesList` can now behave as an iterable (#2345) * Define iterable behaviour for `PropertiesList` * Add `Returns:` to docstring * Add test --- singer_sdk/typing.py | 8 ++++++++ tests/core/test_typing.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index c28791776..7f1b20565 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -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], diff --git a/tests/core/test_typing.py b/tests/core/test_typing.py index 837aff7ff..15d56ccce 100644 --- a/tests/core/test_typing.py +++ b/tests/core/test_typing.py @@ -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