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

Add a TimeConfigBuilder to avoid further breaking changes #46

Merged
merged 5 commits into from
Jul 13, 2023

Conversation

adriangb
Copy link
Member

I noticed while updating pydantic-core that despite efforts to avoid breaking changes adding a field to TimeConfig is indeed a breaking change. I'm adding this TimeConfigBuilder so that we can add more options down the road without a breaking change.

@samuelcolvin I realize we probably think we won't need to add any more options, if you're 100% sure of this please just close this, but I figured since we had 0 a week ago and now have 2...

adriangb added 2 commits July 13, 2023 09:53
I noticed while updating pydantic-core that despite efforts to avoid breaking changes adding a field to TimeConfig is indeed a breaking change. I'm adding this TimeConfigBuilder so that we can add more options down the road withou a breaking change.
@adriangb
Copy link
Member Author

please review

@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #46 (17a3987) into main (7058870) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #46      +/-   ##
==========================================
+ Coverage   99.07%   99.10%   +0.02%     
==========================================
  Files           6        6              
  Lines         862      890      +28     
==========================================
+ Hits          854      882      +28     
  Misses          8        8              
Impacted Files Coverage Δ
src/lib.rs 91.66% <ø> (ø)
src/datetime.rs 100.00% <100.00%> (ø)
src/duration.rs 100.00% <100.00%> (ø)
src/time.rs 97.76% <100.00%> (+0.25%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7058870...17a3987. Read the comment docs.

@samuelcolvin
Copy link
Member

I'm a bit confused by why this is necessary and what it does.

I thought you could just do

TimeConfig { unix_timestamp_offset: Some(123), ..Default::default() };

And extra settings added to TimeConfig wouldn't break your code?

@adriangb
Copy link
Member Author

Yes but then you have to force users to do that, and it’s not immediately obvious, eg in pydantic-core that’s not what we did. The builder pattern is meant precisely to address this situation.

@adriangb
Copy link
Member Author

No real performance impact:

 name                             main ns/iter  variable ns/iter  diff ns/iter   diff %  speedup 
 compare_datetime_error_chrono    40            40                           0    0.00%   x 1.00 
 compare_datetime_error_iso8601   141           144                          3    2.13%   x 0.98 
 compare_datetime_error_speedate  10            10                           0    0.00%   x 1.00 
 compare_datetime_ok_chrono       166           166                          0    0.00%   x 1.00 
 compare_datetime_ok_iso8601      82            82                           0    0.00%   x 1.00 
 compare_datetime_ok_speedate     11            11                           0    0.00%   x 1.00 
 compare_duration_ok_iso8601      46            46                           0    0.00%   x 1.00 
 compare_duration_ok_speedate     31            32                           1    3.23%   x 0.97 
 compare_timestamp_ok_chrono      9             9                            0    0.00%   x 1.00 
 compare_timestamp_ok_speedate    8             7                           -1  -12.50%   x 1.14 
 date                             3             3                            0    0.00%   x 1.00 
 dt_custom_tz                     13            13                           0    0.00%   x 1.00 
 dt_naive                         12            13                           1    8.33%   x 0.92 
 format_date                      38            38                           0    0.00%   x 1.00 
 format_date_time                 180           221                         41   22.78%   x 0.81 
 format_time                      50            49                          -1   -2.00%   x 1.02 
 time                             6             8                            2   33.33%   x 0.75 
 x_combined                       92            96                           4    4.35%   x 0.96

@adriangb adriangb merged commit e133861 into main Jul 13, 2023
@adriangb adriangb deleted the timeconfigbuilder branch July 13, 2023 17:27
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