Skip to content

Conversation

@edgarrmondragon
Copy link
Collaborator

@edgarrmondragon edgarrmondragon commented Apr 11, 2025

Summary by Sourcery

Refactor the type-conforming logic in the _typing module to improve code structure and readability

Enhancements:

  • Restructured the _conform_primitive_property function to use a more modular and extensible type handling approach
  • Introduced separate handler functions for different data types to improve code organization

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 11, 2025

Reviewer's Guide by Sourcery

The pull request refactors the _conform_primitive_property function by introducing a type-to-handler mapping. This change improves code structure and readability by extracting type-specific conversion logic into dedicated functions.

Sequence diagram for _conform_primitive_property function

sequenceDiagram
  participant Caller
  participant _conform_primitive_property
  participant _handle_datetime
  participant _handle_date
  participant _handle_timedelta
  participant _handle_time
  participant _handle_bytes
  participant _handle_numeric

  Caller->>_conform_primitive_property: _conform_primitive_property(elem, property_schema)
  alt elem is datetime.datetime
    _conform_primitive_property->>_handle_datetime: _handle_datetime(elem, property_schema)
    _handle_datetime-->>_conform_primitive_property: return converted elem
  else elem is datetime.date
    _conform_primitive_property->>_handle_date: _handle_date(elem, property_schema)
    _handle_date-->>_conform_primitive_property: return converted elem
  else elem is datetime.timedelta
    _conform_primitive_property->>_handle_timedelta: _handle_timedelta(elem, property_schema)
    _handle_timedelta-->>_conform_primitive_property: return converted elem
  else elem is datetime.time
    _conform_primitive_property->>_handle_time: _handle_time(elem, property_schema)
    _handle_time-->>_conform_primitive_property: return converted elem
  else elem is bytes
    _conform_primitive_property->>_handle_bytes: _handle_bytes(elem, property_schema)
    _handle_bytes-->>_conform_primitive_property: return converted elem
  else elem is float or decimal.Decimal
    _conform_primitive_property->>_handle_numeric: _handle_numeric(elem, property_schema)
    _handle_numeric-->>_conform_primitive_property: return converted elem
  else elem is boolean
    _conform_primitive_property->>_conform_primitive_property: elem != 0
    _conform_primitive_property-->>Caller: return converted elem
  else
    _conform_primitive_property-->>Caller: return elem
  end
Loading

File-Level Changes

Change Details Files
Refactored the _conform_primitive_property function to improve code structure and readability by using a type-to-handler mapping.
  • Introduced a dictionary type_handlers to map data types to their corresponding handler functions.
  • Created dedicated handler functions for datetime, date, timedelta, time, bytes, and numeric types.
  • Simplified the main function by delegating type-specific conversion logic to the handler functions.
  • Added handling for None values at the beginning of the function.
singer_sdk/helpers/_typing.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.51%. Comparing base (2e58db3) to head (15a4921).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2964      +/-   ##
==========================================
+ Coverage   93.47%   93.51%   +0.03%     
==========================================
  Files          69       69              
  Lines        5658     5658              
  Branches      699      693       -6     
==========================================
+ Hits         5289     5291       +2     
+ Misses        264      263       -1     
+ Partials      105      104       -1     
Flag Coverage Δ
core 80.29% <100.00%> (+0.03%) ⬆️
end-to-end 76.98% <68.18%> (+0.19%) ⬆️
optional-components 43.47% <31.81%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link

codspeed-hq bot commented Apr 11, 2025

CodSpeed Performance Report

Merging #2964 will degrade performances by 22.13%

Comparing edgarrmondragon/refactor/better-type-conforming (15a4921) with main (2e58db3)

Summary

❌ 1 regression
✅ 7 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_bench_conform_record_data_types 72.2 ms 92.7 ms -22.13%

@edgarrmondragon
Copy link
Collaborator Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @edgarrmondragon - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The new structure is more readable, but consider if the handler functions could be simplified further, perhaps by sharing common logic.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

edgarrmondragon and others added 2 commits April 11, 2025 21:03
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@edgarrmondragon edgarrmondragon marked this pull request as ready for review April 14, 2025 15:08
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @edgarrmondragon - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding type hints to the elem argument in the handler functions for better clarity.
  • The _handle_datetime function doesn't need the property_schema argument, so you can remove it.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@edgarrmondragon edgarrmondragon added this to the v0.46 milestone Apr 22, 2025
@edgarrmondragon edgarrmondragon self-assigned this Apr 22, 2025
@github-project-automation github-project-automation bot moved this to To Discuss in Office Hours Apr 22, 2025
@edgarrmondragon edgarrmondragon added the Type/Tap Singer taps label Apr 22, 2025
@edgarrmondragon edgarrmondragon modified the milestones: v0.46, v0.47 May 6, 2025
@edgarrmondragon edgarrmondragon marked this pull request as draft June 2, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type/Tap Singer taps

Projects

Status: To Discuss

Development

Successfully merging this pull request may close these issues.

2 participants