[issue29628] struct objects can no longer be pickled

2017-02-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

As a workaround you can make Struct pickleable:

from struct import Struct
import copy, copyreg
def pickle_struct(s):
return Struct, (s.format,)

copyreg.pickle(Struct, pickle_struct)

s1 = Struct('

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29628] struct objects can no longer be pickled

2017-02-22 Thread mesheb82

mesheb82 added the comment:

Thank you.

On Wed, Feb 22, 2017 at 9:22 PM, Serhiy Storchaka 
wrote:

>
> Serhiy Storchaka added the comment:
>
> > When I run the following code on Windows/Linux for < Python 3.6, I have
> no problems.
>
> You have a problem. Did you try to use the copied object? It is a broken
> Struct object.
>
> >>> copied = copy.deepcopy(this_fails)
> >>> copied.format
> >>> copied.size
> -1
> >>> copied.pack(42)
> Traceback (most recent call last):
>   File "", line 1, in 
> struct.error: pack expected -1 items for packing (got 1)
> >>> copied.unpack(b'abcd')
> Traceback (most recent call last):
>   File "", line 1, in 
> struct.error: unpack requires a bytes object of length -1
>
> Copying Struct object never worked. Now it raises an error rather than
> silently creating a broken object.
>
> --
> nosy: +serhiy.storchaka
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29628] struct objects can no longer be pickled

2017-02-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> When I run the following code on Windows/Linux for < Python 3.6, I have no 
> problems.

You have a problem. Did you try to use the copied object? It is a broken Struct 
object.

>>> copied = copy.deepcopy(this_fails)
>>> copied.format
>>> copied.size
-1
>>> copied.pack(42)
Traceback (most recent call last):
  File "", line 1, in 
struct.error: pack expected -1 items for packing (got 1)
>>> copied.unpack(b'abcd')
Traceback (most recent call last):
  File "", line 1, in 
struct.error: unpack requires a bytes object of length -1

Copying Struct object never worked. Now it raises an error rather than silently 
creating a broken object.

--
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29628] struct objects can no longer be pickled

2017-02-22 Thread mesheb82

New submission from mesheb82:

When I run the following code on Windows/Linux for < Python 3.6, I have no 
problems.  When I run in Python 3.6.0, I get the subsequent traceback.

I checked the release notes and only saw the following struct module note 
related to half-floats: Issue #11734

from struct import Struct
import copy
this_fails = Struct('

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com