Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-93627: Align Python implementation of pickle with C implementation of pickle#103035

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
serhiy-storchaka merged 45 commits intopython:mainfromeendebakpt:pickle_93627
Sep 10, 2023

Conversation

eendebakpt
Copy link
Contributor

@eendebakpteendebakpt commentedMar 25, 2023
edited
Loading

In this PR we align the python and C implementation ofpickle module. In this PR we have chosen to modify all implementations to follow the c implementation of pickle conventions: if a method like__reduce_ex_ or__reduce__ is set toNone, aTypeError is raised.

Since the behaviour of the python and c implemenations is not equal, any PR aliging the two cannot be fully backwards compatible. The impact seems limited:

  • No changes are required to the tests (although a few tests are added to verify the new behaviour)
  • The changes impact cases that seem rare (e.g. setting the__reduce_ex__ attribute of a class toNone, instead of creating a method)

Notes:

  • Changes to align thecopy module have been removed from the PR.

Eclips4 reacted with thumbs up emoji
@erlend-aaslanderlend-aasland marked this pull request as draftMarch 28, 2023 08:15
@erlend-aaslanderlend-aasland changed the titleDraft: gh-93627: Align python implementation of pickle with c implementation of picklegh-93627: Align Python implementation of pickle with C implementation of pickleMar 28, 2023
@eendebakpteendebakpt marked this pull request as ready for reviewApril 2, 2023 19:33
@eendebakpt
Copy link
ContributorAuthor

@serhiy-storchaka Will you be able to review the PR?

Copy link
Member

@Eclips4Eclips4 left a comment

Choose a reason for hiding this comment

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

LGTM

@JelleZijlstraJelleZijlstra self-requested a reviewApril 28, 2023 13:21
@CAM-GerlachCAM-Gerlach added the stdlibPython modules in the Lib dir labelApr 28, 2023
def test_pickle_invalid_reduction_method(self):
c = C_None_reduce_ex()
with self.assertRaises(TypeError):
pickle.dumps(c)

Choose a reason for hiding this comment

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

What implementation does it test?

The tests in this module is organized in special way. There are abstract classes which test with the specified implementation specified by class attributes, and there are concrete subclasses which specialize tests for Python and C implementations. It would be better to rewrite your tests in conformance with existing style.

erlend-aasland reacted with thumbs up emoji
Copy link
ContributorAuthor

@eendebakpteendebakptAug 28, 2023
edited
Loading

Choose a reason for hiding this comment

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

@serhiy-storchaka I moved the tests to be part ofAbstractPickleTests,AbstractPicklerUnpicklerObjectTests andAbstractDispatchTableTests. These are included in concrete tests both inside and outside thehas_c_implementation section oftest_pickle.py.

serhiy-storchaka reacted with thumbs up emoji
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

@serhiy-storchaka
Copy link
Member

Thank you for your contribution@eendebakpt. Do you mind to align also the copy module with the pickle module? It is more complex and dangerous change, because we may need to change the order of some operations which is different in copy and pickle modules.

@eendebakpt
Copy link
ContributorAuthor

@serhiy-storchaka If aligning the copy of pickle module is still blocking#91610 I will have a look at the alignment. However, Jelle Zijlstra remarked in#103035 (comment) that the alignment might break some existing code, so we reverted these changes for this PR.@JelleZijlstra was your remark only about the__copy__ or also about theNone/NoValue for the other attributes (e.g.__reduce_ex__,__reduce__)?

@eendebakpt
Copy link
ContributorAuthor

@serhiy-storchaka@JelleZijlstra I created#109498 to get a feeling for the impact of aligning the behaviour of the copy module with the pickle module. Maybe more needs to be aligned, but the PR seems quite straightforward so far.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@erlend-aaslanderlend-aaslanderlend-aasland left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@Eclips4Eclips4Eclips4 approved these changes

Assignees
No one assigned
Labels
stdlibPython modules in the Lib dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@eendebakpt@erlend-aasland@JelleZijlstra@serhiy-storchaka@Eclips4@CAM-Gerlach@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp