[issue37489] pickling instance which inherited from Exception with keyword only parameter

2022-01-06 Thread Irit Katriel


Irit Katriel  added the comment:

> I want to known [...] how to implement the logic in code 2 (passing keyword 
> only parameter to __new__/__init__ when pickling for class inherted from 
> Exception)


This is currently a problem, see issue27015.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> subprocess.CalledProcessError's repr changes based on kwargs, 
and doesn't unpickle

___
Python tracker 

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



[issue37489] pickling instance which inherited from Exception with keyword only parameter

2022-01-06 Thread Irit Katriel


Irit Katriel  added the comment:

> I want to known why it is

It's because Exception implements __reduce__ and that takes precedence over 
__getnewargs_ex__. You can see that with this example:


import pickle

class MyException():
def __init__(self, desc, item):
super().__init__()
self.desc = desc
self.item = item

def __getnewargs_ex__(self):
print('called in {}.__getnewargs_ex__'.format(self.__class__.__name__))
return (self.desc,), self.__dict__

def __reduce__(self):
print('called in {}.__reduce__'.format(self.__class__.__name__))
return MyException, (self.desc, self.item),

e = MyException('testing', item='cpu')
s = pickle.dumps(e, protocol=-1)

x = pickle.loads(s)


Output: called in MyException.__reduce__

--
nosy: +iritkatriel

___
Python tracker 

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



[issue37489] pickling instance which inherited from Exception with keyword only parameter

2019-07-08 Thread liyang


liyang  added the comment:

yesterday i have test two case, first i find the code 1 not execute the 
__init__ when execute loads. second the code 1 and code 2 dumps result s is not 
equal,because the dumps is the buildin function ,so i can't find more 
message.but if the code2 only have keyword parameter the code2 is not raise 
exception. i want to debug the interpreter that can get the reason.

--
nosy: +liyang1...@gmail.com

___
Python tracker 

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



[issue37489] pickling instance which inherited from Exception with keyword only parameter

2019-07-03 Thread liugang


Change by liugang :


--
nosy: +alexandre.vassalotti

___
Python tracker 

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



[issue37489] pickling instance which inherited from Exception with keyword only parameter

2019-07-03 Thread SilentGhost


Change by SilentGhost :


--
nosy: +pitrou
versions: +Python 3.7 -Python 3.5

___
Python tracker 

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



[issue37489] pickling instance which inherited from Exception with keyword only parameter

2019-07-02 Thread liugang


New submission from liugang :

-- code 1
import pickle

class MyException():
def __init__(self, desc, *, item):
super().__init__()
self.desc = desc
self.item = item

def __getnewargs_ex__(self):
print('called in {}.__getnewargs_ex__'.format(self.__class__.__name__))
return (self.desc,), self.__dict__

e = MyException('testing', item='cpu')
s = pickle.dumps(e, protocol=-1)

x = pickle.loads(s)


-- code 2
import pickle

class MyException(Exception):
def __init__(self, desc, *, item):
super().__init__()
self.desc = desc
self.item = item

def __getnewargs_ex__(self):
print('called in {}.__getnewargs_ex__'.format(self.__class__.__name__))
return (self.desc,), self.__dict__

e = MyException('testing', item='cpu')
s = pickle.dumps(e, protocol=-1)

x = pickle.loads(s)

in code 1, the class is inherted from object, __getnewargs_ex__ is called and 
the returned args, kwargs are passed to __new__/__init__ to construct object 
when pickling.

in code 2, the class is inherted from Exception, __getnewargs_ex__ is not 
called, and rasie an exception of "TypeError: __init__() missing 1 required 
positional argument: 'desc'"

I think this is not python issue, it should be the right behavior of Exception. 
I want to known why it is, and how to implement the logic in code 2 (passing 
keyword only parameter to __new__/__init__ when pickling for class inherted 
from Exception)

--
components: Library (Lib)
messages: 347178
nosy: liugang93
priority: normal
severity: normal
status: open
title: pickling instance which inherited from Exception with keyword only 
parameter
type: behavior
versions: Python 3.5

___
Python tracker 

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