classification
Title: Raise a pickleError when convert _functools module to use PyType_FromModuleAndSpec
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: petr.viktorin, serhiy.storchaka, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2020-11-19 15:39 by shihai1991, last changed 2020-11-25 01:10 by shihai1991. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23407 closed shihai1991, 2020-11-19 15:58
Messages (10)
msg381436 - (view) Author: hai shi (shihai1991) * (Python triager) Date: 2020-11-19 15:39
Touch an error when convert _functools module to use PyType_FromModuleAndSpec, the error info:
_pickle.PicklingError: Can't pickle <class 'functools.partial'>: it's not the same object as functools.partial

The related PR: PR3405
msg381437 - (view) Author: hai shi (shihai1991) * (Python triager) Date: 2020-11-19 15:40
Oh, sorry, wrong PR number. the right one: PR23405
msg381440 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-19 16:45
> _pickle.PicklingError: Can't pickle <class 'functools.partial'>: it's not the same object as functools.partial

I don't understand this error. It looks like a bug in functools.

The PR 23407 looks like a workaround rather than a fix.

You should analyze why "cls != obj" conditon is true: why cls is not obj?
msg381675 - (view) Author: hai shi (shihai1991) * (Python triager) Date: 2020-11-23 16:06
> You should analyze why "cls != obj" conditon is true: why cls is not obj?

You are right. I am in the wrong way definitely. It's weird to me.I try to figure it out in this week~
msg381693 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-11-23 19:50
It looks like you imported the functools module twice and have two different classes functools.partial. When you try to import one of them, you found the other one.
msg381707 - (view) Author: hai shi (shihai1991) * (Python triager) Date: 2020-11-24 04:59
> It looks like you imported the functools module twice and have two different classes functools.partial. When you try to import one of them, you found the other one.

You are right. Serhiy:)

The key point is `import_helper.import_fresh_module()`.
```
import functools
from test.support import import_helper

partial = functools.partial
new_functools = import_helper.import_fresh_module('functools',
                                                  fresh=['_functools'])
new_partial = new_functools.partial
assert(partial == new_partial)
```
Succeed in master, failed in PR23405.
msg381752 - (view) Author: hai shi (shihai1991) * (Python triager) Date: 2020-11-24 16:26
I updated the test_functools.py in PR23405, the CI have all passed.
msg381760 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-24 17:26
> I updated the test_functools.py in PR23405, the CI have all passed.

Does it mean that this issue is invalid and can be closed?
msg381763 - (view) Author: hai shi (shihai1991) * (Python triager) Date: 2020-11-24 17:48
> Does it mean that this issue is invalid and can be closed?

I think it's can be closed if I can update test_functools.py in PR23405 :)
msg381778 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-24 22:20
> I think it's can be closed if I can update test_functools.py in PR23405 :)

Well, it's your issue, you can close the attached PR and close the issue.
History
Date User Action Args
2020-11-25 01:10:22shihai1991setstatus: open -> closed
stage: patch review -> resolved
2020-11-25 01:10:08shihai1991setresolution: not a bug
2020-11-24 22:20:23vstinnersetmessages: + msg381778
2020-11-24 17:48:50shihai1991setmessages: + msg381763
2020-11-24 17:26:23vstinnersetmessages: + msg381760
2020-11-24 16:26:14shihai1991setmessages: + msg381752
2020-11-24 05:00:00shihai1991setmessages: + msg381707
2020-11-23 19:50:19serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg381693
2020-11-23 16:06:10shihai1991setmessages: + msg381675
2020-11-19 16:45:56vstinnersetmessages: + msg381440
2020-11-19 15:58:31shihai1991setkeywords: + patch
stage: patch review
pull_requests: + pull_request22300
2020-11-19 15:40:09shihai1991setmessages: + msg381437
2020-11-19 15:39:07shihai1991create