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

feat: PropertiesList can now behave as an iterable #2345

merged 3 commits into from
Mar 26, 2024

Conversation

ReubenFrankel
Copy link
Contributor

@ReubenFrankel ReubenFrankel commented Mar 26, 2024

In tap-spotify, all schema objects inherit from a CustomObject class that offers some convenience methods, including allowing one custom object to extend others in order to produce a merged schema. The reason this class exists was because at the time there wasn't an obvious way to merge two or more property lists together, but I think its a pretty simple addition to get the functionality natively.

Given that, for example, Rank, SyncedAt, Track and AudioFeatures are no longer classes extending CustomObject and instead are just PropertiesList instances

track.py

"""Schema definitions for track objects."""

from singer_sdk import typing as th

from tap_spotify.schemas.album import AlbumObject
from tap_spotify.schemas.artist import ArtistObject
from tap_spotify.schemas.external import ExternalIdObject, ExternalUrlObject
from tap_spotify.schemas.restriction import RestrictionObject as TrackRestrictionObject


TrackObject = th.PropertiesList(
    th.Property("album", AlbumObject),
    th.Property("artists", th.ArrayType(ArtistObject)),
    th.Property("available_markets", th.ArrayType(th.StringType)),
    th.Property("disc_number", th.IntegerType),
    th.Property("duration_ms", th.IntegerType),
    th.Property("explicit", th.BooleanType),
    th.Property("external_ids", ExternalIdObject()),
    th.Property("external_urls", ExternalUrlObject),
    th.Property("href", th.StringType),
    th.Property("id", th.StringType),
    th.Property("is_local", th.BooleanType),
    th.Property("is_playable", th.BooleanType),
    # th.Property("linked_from", TrackObject),  # noqa: ERA001
    th.Property("name", th.StringType),
    th.Property("popularity", th.IntegerType),
    th.Property("preview_url", th.StringType),
    th.Property("restrictions", TrackRestrictionObject),
    th.Property("track_number", th.IntegerType),
    th.Property("type", th.StringType),
    th.Property("uri", th.StringType),
)

then

schema = TrackObject.extend_with(Rank, SyncedAt, AudioFeaturesObject).schema

becomes

schema = th.PropertiesList(*TrackObject, *Rank, *SyncedAt, *AudioFeaturesObject).to_dict()

📚 Documentation preview 📚: https://meltano-sdk--2345.org.readthedocs.build/en/2345/

Copy link

codspeed-hq bot commented Mar 26, 2024

CodSpeed Performance Report

Merging #2345 will not alter performance

⚠️ No base runs were found

Falling back to comparing ReubenFrankel:feature/properties-list-iter (fe17499) with main (5ec5a18)

Summary

✅ 6 untouched benchmarks

@ReubenFrankel
Copy link
Contributor Author

>>> from singer_sdk import typing as th
>>> 
>>> pl1 = th.PropertiesList(th.Property("first", th.StringType))
>>> pl2 = th.PropertiesList(th.Property("second", th.IntegerType))
>>> pl3 = th.PropertiesList(th.Property("third", th.BooleanType))
>>> 
>>> th.PropertiesList(*pl1, *pl2, *pl3).to_dict()
{'type': 'object', 'properties': {'first': {'type': ['string', 'null']}, 'second': {'type': ['integer', 'null']}, 'third': {'type': ['boolean', 'null']}}}
>>> 
>>> th.PropertiesList(*pl2, *pl3, *pl1).to_dict()
{'type': 'object', 'properties': {'second': {'type': ['integer', 'null']}, 'third': {'type': ['boolean', 'null']}, 'first': {'type': ['string', 'null']}}}
>>> 

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.76%. Comparing base (61a5727) to head (fe17499).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2345   +/-   ##
=======================================
  Coverage   88.76%   88.76%           
=======================================
  Files          54       54           
  Lines        4769     4771    +2     
  Branches      928      928           
=======================================
+ Hits         4233     4235    +2     
  Misses        374      374           
  Partials      162      162           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@edgarrmondragon edgarrmondragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

@edgarrmondragon edgarrmondragon changed the title feat: Define iterable behaviour for PropertiesList feat: PropertiesList can now be iterated over Mar 26, 2024
@edgarrmondragon edgarrmondragon changed the title feat: PropertiesList can now be iterated over feat: PropertiesList can now behave as an iterable Mar 26, 2024
@edgarrmondragon edgarrmondragon added this pull request to the merge queue Mar 26, 2024
Merged via the queue into meltano:main with commit b9622c7 Mar 26, 2024
30 checks passed
@ReubenFrankel ReubenFrankel deleted the feature/properties-list-iter branch March 26, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants