[Python-Dev] Re: Method __func__ objects are unpicklable

2022-06-10 Thread Brett Cannon
I believe a lot of people use https://pypi.org/project/cloudpickle/ thanks
to its support for pickling functions.

On Fri, Jun 10, 2022 at 4:56 AM haael  wrote:

>
>
> During some sophisticated pickling I noticed that method `__func__`
> objects are unpicklable, because they share the name with the bound
> method object itself.
>
>
> ```
> from pickle import dumps
>
> class A:
>  @classmethod
>  def b(cls):
>  pass
>
> print(A.b) # >
> print(A.b.__func__) # 
>
> dumps(A.b) # works
> dumps(A.b.__func__) # breaks
> # >Traceback (most recent call last):
> # >  File "", line 1, in 
> # >_pickle.PicklingError: Can't pickle :
> # >it's not the same object as __main__.A.b
> ```
>
>
> The last call compains that global symbol "A.b" is not the same object
> as `A.b.__func__`.
>
> Everything would work if the `__func__` objects had the suffix
> ".__func__" in their qualname.
>
> Actually setting the qualname of the `__func__` object makes it
> picklable, but then the bound method object is unpicklable, as it
> inherits the name from the `__func__`. It would be good if they were
> separate.
>
> This is an attempt at emulating the desired behavior:
>
>
> ```
> from pickle import dumps
>
> class A:
>  pass
>
> def c(cls):
>  pass
>
> A.c = lambda: c(A)
> A.c.__qualname__ = "A.c"
> A.c.__name__ = "c"
> A.c.__self__ = A
> A.c.__func__ = c
> A.c.__func__.__qualname__ = "A.c.__func__"
>
> print(A.c) # 
> print(A.c.__func__) # 
>
> dumps(A.c) # works
> dumps(A.c.__func__) # works
> ```
>
>
> Can we make the `__func__` objects picklable this way?
>
>
> haael
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/N2J6MVLURTBAB5PJLJG3LO6U4PTPJMU2/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NSBJC3266COHPPTNJMLVDHNW4AS7E4QE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Summary of Python tracker Issues

2022-06-10 Thread Python tracker

ACTIVITY SUMMARY (2022-06-03 - 2022-06-10)
Python tracker at https://bugs.python.org/

To view or respond to any of the issues listed below, click on the issue.
Do NOT respond to this message.

Issues counts and deltas:
  open7146 ( +0)
  closed 51841 ( +0)
  total  58987 ( +0)

Open issues with patches: 2890 


Most recent 15 issues with no replies (15)
==

#47258: Python 3.10 hang at exit in drop_gil() (due to resource warnin
https://bugs.python.org/issue47258

#47256: re: limit the maximum capturing group to 1,073,741,823, reduce
https://bugs.python.org/issue47256

#47253: LOAD_GLOBAL instruction with wrong source position
https://bugs.python.org/issue47253

#47252: socket.makefile documentation is missing data regarding the 'b
https://bugs.python.org/issue47252

#47251: Merge BINARY_SUBSCR_LIST_INT with BINARY_SUBSCR_LIST_TUPLE
https://bugs.python.org/issue47251

#47244: email.utils.formataddr does not respect double spaces
https://bugs.python.org/issue47244

#47242: Annoying white bar in IDLE (line 457 in sidebar.py)
https://bugs.python.org/issue47242

#47241: [C API] Move the PyCodeObject structure to the internal C API 
https://bugs.python.org/issue47241

#47238: Python threading.Event().wait() depends on the system time
https://bugs.python.org/issue47238

#47236: Document types.CodeType.replace() changes about co_exceptionta
https://bugs.python.org/issue47236

#47228: Document that na??ve datetime objects represent local time
https://bugs.python.org/issue47228

#47222: subprocess.Popen() should allow capturing output and sending i
https://bugs.python.org/issue47222

#47219: asyncio with two interpreter instances
https://bugs.python.org/issue47219

#47218: adding name to lzmafile
https://bugs.python.org/issue47218

#47217: adding name to BZ2File
https://bugs.python.org/issue47217



Most recent 15 issues waiting for review (15)
=

#47256: re: limit the maximum capturing group to 1,073,741,823, reduce
https://bugs.python.org/issue47256

#47255: Many broken :meth: roles in the docs
https://bugs.python.org/issue47255

#47254: enhanced dir?
https://bugs.python.org/issue47254

#47251: Merge BINARY_SUBSCR_LIST_INT with BINARY_SUBSCR_LIST_TUPLE
https://bugs.python.org/issue47251

#47243: Duplicate entry in 'Objects/unicodetype_db.h'
https://bugs.python.org/issue47243

#47233: show_caches option affects code positions reported by dis.get_
https://bugs.python.org/issue47233

#47222: subprocess.Popen() should allow capturing output and sending i
https://bugs.python.org/issue47222

#47218: adding name to lzmafile
https://bugs.python.org/issue47218

#47217: adding name to BZ2File
https://bugs.python.org/issue47217

#47216: adding mtime option to gzip open()
https://bugs.python.org/issue47216

#47215: Add "unstable" frame stack api
https://bugs.python.org/issue47215

#47208: Support libffi implementations that cannot support invocations
https://bugs.python.org/issue47208

#47205: posix.sched_{get|set}affinity(-1) no longer returns ProcessLoo
https://bugs.python.org/issue47205

#47200: Add ZipInfo.mode property
https://bugs.python.org/issue47200

#47199: multiprocessing: micro-optimize Connection.send_bytes() method
https://bugs.python.org/issue47199
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/WB3V7R2SIVLOHMBF4CTOUS6236J5LKAS/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Method __func__ objects are unpicklable

2022-06-10 Thread Joao S. O. Bueno
This is not just about the content of the name attributes: ;bound methods
do contain a reference to the specific instance
they are bound too - which is not retrievable (or maybe is through some
dunder attribute) - this instance has to be pickled, transported
and its reference updated on unpickling.

On Fri, Jun 10, 2022 at 9:00 AM haael  wrote:

>
>
> During some sophisticated pickling I noticed that method `__func__`
> objects are unpicklable, because they share the name with the bound
> method object itself.
>
>
> ```
> from pickle import dumps
>
> class A:
>  @classmethod
>  def b(cls):
>  pass
>
> print(A.b) # >
> print(A.b.__func__) # 
>
> dumps(A.b) # works
> dumps(A.b.__func__) # breaks
> # >Traceback (most recent call last):
> # >  File "", line 1, in 
> # >_pickle.PicklingError: Can't pickle :
> # >it's not the same object as __main__.A.b
> ```
>
>
> The last call compains that global symbol "A.b" is not the same object
> as `A.b.__func__`.
>
> Everything would work if the `__func__` objects had the suffix
> ".__func__" in their qualname.
>
> Actually setting the qualname of the `__func__` object makes it
> picklable, but then the bound method object is unpicklable, as it
> inherits the name from the `__func__`. It would be good if they were
> separate.
>
> This is an attempt at emulating the desired behavior:
>
>
> ```
> from pickle import dumps
>
> class A:
>  pass
>
> def c(cls):
>  pass
>
> A.c = lambda: c(A)
> A.c.__qualname__ = "A.c"
> A.c.__name__ = "c"
> A.c.__self__ = A
> A.c.__func__ = c
> A.c.__func__.__qualname__ = "A.c.__func__"
>
> print(A.c) # 
> print(A.c.__func__) # 
>
> dumps(A.c) # works
> dumps(A.c.__func__) # works
> ```
>
>
> Can we make the `__func__` objects picklable this way?
>
>
> haael
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/N2J6MVLURTBAB5PJLJG3LO6U4PTPJMU2/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/TZ4DCYPHB2B7U7HOMQG2C4AYVKS3KONI/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Method __func__ objects are unpicklable

2022-06-10 Thread haael




During some sophisticated pickling I noticed that method `__func__` 
objects are unpicklable, because they share the name with the bound 
method object itself.



```
from pickle import dumps

class A:
@classmethod
def b(cls):
pass

print(A.b) # >
print(A.b.__func__) # 

dumps(A.b) # works
dumps(A.b.__func__) # breaks
# >Traceback (most recent call last):
# >  File "", line 1, in 
# >_pickle.PicklingError: Can't pickle : 
# >it's not the same object as __main__.A.b

```


The last call compains that global symbol "A.b" is not the same object 
as `A.b.__func__`.


Everything would work if the `__func__` objects had the suffix 
".__func__" in their qualname.


Actually setting the qualname of the `__func__` object makes it 
picklable, but then the bound method object is unpicklable, as it 
inherits the name from the `__func__`. It would be good if they were 
separate.


This is an attempt at emulating the desired behavior:


```
from pickle import dumps

class A:
pass

def c(cls):
pass

A.c = lambda: c(A)
A.c.__qualname__ = "A.c"
A.c.__name__ = "c"
A.c.__self__ = A
A.c.__func__ = c
A.c.__func__.__qualname__ = "A.c.__func__"

print(A.c) # 
print(A.c.__func__) # 

dumps(A.c) # works
dumps(A.c.__func__) # works
```


Can we make the `__func__` objects picklable this way?


haael

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/N2J6MVLURTBAB5PJLJG3LO6U4PTPJMU2/
Code of Conduct: http://python.org/psf/codeofconduct/