[issue30005] Pickling and copying exceptions doesn't preserve non-__dict__ attributes

2021-06-27 Thread Irit Katriel


Irit Katriel  added the comment:

See also issue43460, issue32696, issue29466.

--
nosy: +iritkatriel
versions: +Python 3.11 -Python 2.7, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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



[issue30005] Pickling and copying exceptions doesn't preserve non-__dict__ attributes

2017-04-05 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
dependencies: +Pickling and copying ImportError doesn't preserve name and path

___
Python tracker 

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



[issue30005] Pickling and copying exceptions doesn't preserve non-__dict__ attributes

2017-04-05 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Pickling and copying exceptions preserves only __dict__ attributes.

This includes writeable internal fields initialized in constructor:

>>> import pickle, copy
>>> e = StopIteration(12)
>>> e.value = 34
>>> e.value
34
>>> e2 = pickle.loads(pickle.dumps(e, 4))
>>> e2.value
12
>>> e2 = copy.copy(e)
>>> e2.value
12

And __slots__:

>>> class E(Exception): __slots__ = ('x', 'y')
... 
>>> e = E()
>>> e.x = 12
>>> e.x
12
>>> e2 = pickle.loads(pickle.dumps(e, 4))
>>> e2.x
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: x
>>> e2 = copy.copy(e)
>>> e2.x
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: x

__context__, __cause__ and __traceback__ are lost too (see issue29466).

Issue26579 is similar, but resolving it will not resolve this issue since 
BaseException has its own __reduce__ and __setstate__ implementations.

The solution of this issue will look similar to issue29998, but more complex 
and general.

--
components: Interpreter Core
messages: 291212
nosy: alexandre.vassalotti, serhiy.storchaka
priority: normal
severity: normal
stage: needs patch
status: open
title: Pickling and copying exceptions doesn't preserve non-__dict__ attributes
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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