8000 Make TzInfo picklable by adriangb · Pull Request #770 · pydantic/pydantic-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make TzInfo picklable #770

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

Merged
merged 8 commits into from
Jul 13, 2023
Merged

Make TzInfo picklable #770

merged 8 commits into from
Jul 13, 2023

Conversation

adriangb
Copy link
Member
@adriangb adriangb commented Jul 13, 2023

Fixes #589

Selected Reviewer: @samuelcolvin

@codspeed-hq
Copy link
codspeed-hq bot commented Jul 13, 2023

CodSpeed Performance Report

Merging #770 will not alter performance

Comparing pickle-tzinfo (12f6962) with main (3345f3e)

Summary

✅ 126 untouched benchmarks

@codecov
Copy link
codecov bot commented Jul 13, 2023

Codecov Report

Merging #770 (8c33771) into main (3345f3e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #770   +/-   ##
=======================================
  Coverage   93.66%   93.66%           
=======================================
  Files          99       99           
  Lines       14247    14253    +6     
  Branches       25       25           
=======================================
+ Hits        13344    13350    +6     
  Misses        897      897           
  Partials        6        6           
Impacted Files Coverage Δ
src/input/mod.rs 100.00% <ø> (ø)
src/input/datetime.rs 98.79% <100.00%> (+0.01%) ⬆️
src/lib.rs 100.00% <100.00%> (ø)

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 3345f3e...8c33771. Read the comment docs.

@adriangb
Copy link
Member Author

please review

Comment on lines +494 to +515
def test_tz_hash() -> None:
v = SchemaValidator(core_schema.datetime_schema())
lookup: Dict[datetime, str] = {}
for day in range(1, 10):
input_str = f'2022-06-{day:02}T12:13:14-12:1 8000 5'
validated = v.validate_python(input_str)
lookup[validated] = input_str

assert len(lookup) == 9
assert (
lookup[datetime(2022, 6, 8, 12, 13, 14, tzinfo=timezone(timedelta(hours=-12, minutes=-15)))]
== '2022-06-08T12:13:14-12:15'
)


def test_tz_cmp() -> None:
v = SchemaValidator(core_schema.datetime_schema())
validated1 = v.validate_python('2022-06-08T12:13:14-12:15')
validated2 = v.validate_python('2022-06-08T12:13:14-12:14')

assert validated1 > validated2
assert validated2 < validated1
Copy link
Member Author

Choose a reason for hiding this comment

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

These are just testing existing properties

Copy link
Member
@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise LGTM.

@@ -93,6 +94,7 @@ fn _pydantic_core(py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<PyMultiHostUrl>()?;
m.add_class::<ArgsKwargs>()?;
m.add_class::<SchemaSerializer>()?;
m.add_class::<TzInfo>()?;
Copy link
Member

Choose a reason for hiding this comment

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

does this actually need to be exported? If it does, we should have a test for importing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does so that it can be unpickled

Copy link
Member Author

Choose a reason for hiding this comment

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

The pickle test is already testing that it can be imported

adriangb and others added 3 commits July 13, 2023 12:22
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
@adriangb adriangb enabled auto-merge (squash) July 13, 2023 17:24
@adriangb adriangb merged commit f499c73 into main < 7896 /span> Jul 13, 2023
@adriangb adriangb deleted the pickle-tzinfo branch July 13, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error pickling pydantic-core internal TzInfo type
2 participants
0