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 Serialize, Deserialize for Py<T> #1366

Merged
merged 1 commit into from Jan 12, 2021

Conversation

daniil-konovalenko
Copy link
Contributor

@daniil-konovalenko daniil-konovalenko commented Jan 6, 2021

David Hewitt wrote in #1358

As for Serialize / Deserialize for Py<T> - I'm beginning to think that PyO3 should have an optional serde feature to support this...

I thought this too and hacked together a "serde" feature that includes implementations of Serialize and Deserialize for Py<T>

TODO:

  • an entry in CHANGELOG.md
  • docs to all new functions and / or detail in the guide
  • tidy up tests

@daniil-konovalenko
Copy link
Contributor Author

daniil-konovalenko commented Jan 7, 2021

@davidhewitt hi, could you please take a look at this? The PR is by no means ready for the real review, but I would really appreciate your feedback on the general implementation idea.

The thing that bothers me the most is error handling — should we just convert pyo3 errors to String and create custom serde errors from it, or maybe we should attach more context to them somehow?

@kngwyu
Copy link
Member

kngwyu commented Jan 7, 2021

Thanks!

The PR is by no means ready for the real review

I don't see any clear problem... what do you have in your mind as a blocker?

The thing that bothers me the most is error handling

I think both se and de would rarely fail and we don't have to take care of it so seriously.

@daniil-konovalenko
Copy link
Contributor Author

daniil-konovalenko commented Jan 7, 2021

Thank you for the quick response!

I don't see any clear problem... what do you have in your mind as a blocker?

I was anxious about error handling (I'm new to Rust), and the tests could be better, but the implementation itself looks ready for review.

Also I haven't written the docs yet, but this doesn't block the review of course

@daniil-konovalenko daniil-konovalenko marked this pull request as ready for review January 7, 2021 16:26
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks very much for this!

TBH I agree, the code, tests and docs all look very good, so I'm happy! I just have some very minor nits.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -28,6 +28,27 @@ These features are an extension of the `abi3` feature to specify the exact minim

See the [building and distribution](building_and_distribution.md#minimum-python-version-for-abi3) section for further detail.

### `serde`
Copy link
Member

Choose a reason for hiding this comment

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

This needs to go in the "Advanced Features" section (which should maybe be renamed to "Other Features") as this feature could be useful in the embedding case too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks!

Cargo.toml Outdated

[dev-dependencies]
assert_approx_eq = "1.1.0"
trybuild = "1.0.23"
rustversion = "1.0"
proptest = { version = "0.10.1", default-features = false, features = ["std"] }
# features needed to run the PyO3 test suite
pyo3 = { path = ".", default-features = false, features = ["macros", "auto-initialize"] }
pyo3 = { path = ".", default-features = false, features = ["macros", "auto-initialize", "serde"] }
Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking, we don't need this feature to run the tests - they straight up don't work without the other features enabled.

I'd rather just see the serde feature added to the list of features tested in ci.yml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip! Added serde to ci.yml

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@kngwyu unless you think otherwise, I'm going to merge this after we release 0.13.1, to allow some time to get feedback on this on master before this makes a release.

CHANGELOG.md Outdated Show resolved Hide resolved
@davidhewitt
Copy link
Member

I force-pushed a squash and rebase; will merge assuming CI is happy. Thanks again for the contribution!

@davidhewitt davidhewitt merged commit ad40632 into PyO3:master Jan 12, 2021
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.

None yet

3 participants