refactor: Simplified type-conforming logic
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
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
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. |
|
singer_sdk/helpers/_typing.py |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon 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 issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon 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 dismisson 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 reviewto trigger a new review! -
Generate a plan of action for an issue: Comment
@sourcery-ai planon 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
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: 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%) |
:arrow_up: |
| end-to-end | 76.98% <68.18%> (+0.19%) |
:arrow_up: |
| optional-components | 43.47% <31.81%> (+0.10%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
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
:warning: 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% |
@sourcery-ai review