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

Implement FromStr for data types #49

Merged
merged 3 commits into from
Dec 13, 2023
Merged

Conversation

TehPers
Copy link
Contributor

@TehPers TehPers commented Aug 5, 2023

Implements FromStr for Date, DateTime, Duration, and Time by delegating to each type's respective parse_str method.

Date and DateTime also have parse_str_rfc3339 (parse_str accepts a Unix timestamp as well). This PR uses the more permissive of the two to accommodate for more input formats. Users of the library can still explicitly call parse_str_rfc3339 directly themselves for more strict parsing.

Closes #48

@samuelcolvin samuelcolvin reopened this Aug 5, 2023
@codecov
Copy link

codecov bot commented Aug 5, 2023

Codecov Report

Merging #49 (f3c692b) into main (4ea725c) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #49      +/-   ##
==========================================
+ Coverage   99.11%   99.12%   +0.01%     
==========================================
  Files           6        6              
  Lines         902      918      +16     
==========================================
+ Hits          894      910      +16     
  Misses          8        8              
Files Coverage Δ
src/date.rs 100.00% <100.00%> (ø)
src/datetime.rs 100.00% <100.00%> (ø)
src/duration.rs 100.00% <100.00%> (ø)
src/time.rs 97.81% <100.00%> (+0.02%) ⬆️

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 4ea725c...f3c692b. Read the comment docs.

@samuelcolvin
Copy link
Member

Great if you could add tests, just one or two would be great.

@TehPers
Copy link
Contributor Author

TehPers commented Aug 5, 2023

I hooked tests into param_tests since all the types implement FromStr now and have parse_str methods. Future types could opt out of this functionality in the macro (or current types could opt-in).

@davidhewitt
Copy link
Contributor

It looks to me like the tests are added and passing, so I will assume this is now fine to merge.

@davidhewitt davidhewitt merged commit ef53708 into pydantic:main Dec 13, 2023
7 checks passed
@TehPers TehPers deleted the impl-fromstr branch December 24, 2023 21:02
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.

Implement FromStr for types
3 participants