Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unpickle patch: cannot instantiate 'WindowsPath' on your system

729 views
Skip to first unread message

ed...@openmail.cc

unread,
Oct 23, 2019, 3:25:10 PM10/23/19
to
Hello,

I hope that I am writing to the right list.
Python 3.7.4 on GNU/Linux Parabola 5.3.1-gnu-1 x86_64 AMD

Issue:
I got a .pickle which had some WindowsPath inside. I was unable to
unpickle like this:

┌────
│ import pickle as pkl
│ from pathlib import Path, PureWindowsPath, PurePath, PurePosixPath,
WindowsPath, PosixPath
│ fname = "ohw_analysis.pickle"
│ # fpath = PureWindowsPath(fname)
│ fpath = Path(fname)
│ with open(fpath, "rb") as fd:
│ # Works in Winbug$ only
│ ohw_analysis = pkl.load(fd)
└────

I tried to create my own class to override =_new= in =Path=, but that
did not work, because (I assume that) the pickle data was pointing to
=pathlib=. I did not know how to solve this, so I modified the code for
pathlib.py

Solution:
The modification allowed me to unpickle the file, and I think that it
would not break =pathlib=. I have seen this issue reported elsewhere,
and I thought that it could be useful to others.

Extra:
I really hope that this is useful. Although I am not asking for help, if
there was a better solution, let me know. I don't want a Github account
(Micro$oft).

Thanks!
0 new messages