cloudpipe / cloudpickle

Extended pickling support for Python objects
Other
1.64k stars 167 forks source link

Exception line numbering is wrong in Python 3.10.8 #490

Closed henrifroese closed 1 year ago

henrifroese commented 1 year ago

Hi 👋

Behaviour in 3.8:

Python 3.8.9 (default, Apr 13 2022, 08:48:06) 
Type "help", "copyright", "credits" or "license" for more information.
>>> def add(x, y):
...     if x == 2:
...         raise Exception(f'Kapput: problem with x={x} and y={y}')
...     else:
...         return x + y
... 
>>> add(2, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in add
Exception: Kapput: problem with x=2 and y=2
>>> import cloudpickle
>>> cloudpickle.loads(cloudpickle.dumps(add))(2, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in add
Exception: Kapput: problem with x=2 and y=2

Behaviour in 3.10:

Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def add(x, y):
...     if x == 2:
...         raise Exception(f'Kapput: problem with x={x} and y={y}')
...     else:
...         return x + y
... 
>>> import cloudpickle
>>> add(2, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in add
Exception: Kapput: problem with x=2 and y=2
>>> cloudpickle.loads(cloudpickle.dumps(add))(2, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in add
Exception: Kapput: problem with x=2 and y=2

Note the difference in the second line from the bottom: In 3.10, the line number is wrong.

This works fine with plain Python pickle.

ogrisel commented 1 year ago

Interesting bug. I don't have time to investigate myself but feel free to open a PR if you find the fix.

henrifroese commented 1 year ago

Hey, sorry forgot to update here - upgrading to the newest version of cloudpickle fixes this already 😄

ogrisel commented 1 year ago

Great news!