[issue32696] Fix pickling exceptions with multiple arguments

2022-01-14 Thread Ziga Seilnacht


Change by Ziga Seilnacht :


--
nosy:  -zseil

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2022-01-14 Thread Zefir-13000


Change by Zefir-13000 :


--
nosy: +Zefir-13000
nosy_count: 11.0 -> 12.0
pull_requests: +28801
pull_request: https://github.com/python/cpython/pull/30602

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2022-01-06 Thread Irit Katriel


Change by Irit Katriel :


--
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



[issue32696] Fix pickling exceptions with multiple arguments

2022-01-06 Thread Georg Brandl


Change by Georg Brandl :


--
nosy:  -georg.brandl

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2022-01-06 Thread Irit Katriel


Irit Katriel  added the comment:

This isn't really an issue with exceptions, it's just that __reduce__ goes out 
of sync with the object's constructor signature. Here's a simple example of the 
same:

class Base:
   def __init__(self, msg):
   self.msg = msg

   def __reduce__(self):
   return type(self), (self.msg,)

class Derived(Base):
   def __init__(self, a, b):
   super().__init__(f'{a}|{b}')

x = Derived('a', 'b')
assert x.msg == 'a|b'
y = pickle.dumps(x, -1)
z = pickle.loads(y)

---
Output:

Traceback (most recent call last):
  File "/Users/iritkatriel/src/cpython/zz.py", line 22, in 
z = pickle.loads(y)
^^^
TypeError: Derived.__init__() missing 1 required positional argument: 'b'

If I define __reduce__ on Derived to return an arg tuple of the right length 
for its __init__, it works:

class Derived(Base):
   def __init__(self, a, b):
   super().__init__(f'{a}|{b}')

   def __reduce__(self):
   return type(self), tuple(self.msg.split('|'))

But note that this is not something we could make the base class do, it has no 
way of finding out what the semantics of the derived class constructor args are.

--

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2021-11-19 Thread 4-launchpad-kalvdans-no-ip-org


Change by 4-launchpad-kalvdans-no-ip-org :


--
nosy: +4-launchpad-kalvdans-no-ip-org

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2021-06-27 Thread Irit Katriel


Irit Katriel  added the comment:

See also issue43460, issue30005, issue29466

--

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2021-06-18 Thread Henk-Jaap Wagenaar


Henk-Jaap Wagenaar  added the comment:

It seems like the example in the OP now works (persist both arguments), but 
Irit's/Kirill's (create a msg) fails (I am running 3.9).

--
nosy: +cryvate

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2021-06-18 Thread Irit Katriel


Irit Katriel  added the comment:

This is still the same in 3.11:

>>> import pickle
>>> class CustomException(Exception):
... def __init__(self, arg1, arg2):
... msg = "Custom message {} {}".format(arg1, arg2)
... super().__init__(msg)
...
>>> obj_dump = pickle.dumps(CustomException("arg1", "arg2"))
>>> obj = pickle.loads(obj_dump)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: CustomException.__init__() missing 1 required positional argument: 
'arg2'
>>>

--
nosy: +iritkatriel
versions: +Python 3.11 -Python 2.7

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-10-29 Thread Benoit Pierre


Change by Benoit Pierre :


--
nosy: +benoit-pierre

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-10-11 Thread Orivej Desh


Change by Orivej Desh :


--
nosy: +orivej

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-04-12 Thread Jason R. Coombs

Jason R. Coombs  added the comment:

Kirill, see https://bugs.python.org/issue1692335#msg310951 in the related issue 
for one possible way to work around the issue on Python 3.

--

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-04-12 Thread Kirill Matsaberydze

Kirill Matsaberydze  added the comment:

Hi, I encounter similar behavior in python 3.6.5 with following code:

import pickle
class CustomException(Exception):
def __init__(self, arg1, arg2):
msg = "Custom message {} {}".format(arg1, arg2)
super().__init__(msg)


obj_dump = pickle.dumps(CustomException("arg1", "arg2"))
obj = pickle.loads(obj_dump)

Traceback (most recent call last):
  File "", line 1, in 
TypeError: __init__() missing 1 required positional argument: 'arg2'

So it looks like it not only python 2.7 problem

--
nosy: +Kirill Matsaberydze

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-01-28 Thread Ofer

New submission from Ofer :

Pickling exceptions fails when a custom exception class requires multiple 
arguments.

import pickle
class MultipleArgumentsError(Exception):
def __init__(self, a, b):
self.a = a
self.b = b

pickle.loads(pickle.dumps(MultipleArgumentsError('a', 'b')))

this code produces the following error:

Traceback (most recent call last):
  File "/tmp/multiple_arguments_exception.py", line 8, in 
pickle.loads(pickle.dumps(MultipleArgumentsError('a', 'b')))
  File 
"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py",
 line 1388, in loads
return Unpickler(file).load()
  File 
"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py",
 line 864, in load
dispatch[key](self)
  File 
"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py",
 line 1139, in load_reduce
value = func(*args)
TypeError: __init__() takes exactly 3 arguments (2 given)


The same error occurs when using a built-in module like subprocess:
>>> import subprocess, pickle
>>> try:
...   subprocess.check_call(['python', '-c', 'raise SystemExit(1)'])
... except Exception as e:
...   pickle.loads(pickle.dumps(e))
... 


Related issue: https://bugs.python.org/issue1692335

--
components: Interpreter Core
messages: 310963
nosy: alexandre.vassalotti, georg.brandl, jason.coombs, sbt, slallum, zseil
priority: normal
severity: normal
status: open
title: Fix pickling exceptions with multiple arguments
type: behavior
versions: Python 2.7

___
Python tracker 

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