[New-bugs-announce] [issue41395] pickle and pickletools cli interface doesn't close input and output file.
Karthikeyan Singaravelan
report at bugs.python.org
Sat Jul 25 10:12:10 EDT 2020
New submission from Karthikeyan Singaravelan <tir.karthi at gmail.com>:
pickle and pickletools use argparse with FileType which is not automatically closed. Other cli interfaces like json [0], ast [1] use context manager to close filetype objects.
pickle : https://github.com/python/cpython/blob/af08db7bac3087aac313d052c1a6302bee7c9c89/Lib/pickle.py#L1799
mypickle
>>> import pickle
>>> with open("mypickle", "wb") as f: pickle.dump({"a": 1}, f)
./python -Wall -m pickle mypickle
{'a': 1}
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='mypickle'>
pickletools : https://github.com/python/cpython/blob/af08db7bac3087aac313d052c1a6302bee7c9c89/Lib/pickletools.py#L2850-L2855
./python -Wall -m pickletools mypickle -o mypickle.py
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='mypickle'>
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='mypickle.py' mode='w' encoding='UTF-8'>
[0] https://github.com/python/cpython/blob/af08db7bac3087aac313d052c1a6302bee7c9c89/Lib/json/tool.py#L61
[1] https://github.com/python/cpython/blob/af08db7bac3087aac313d052c1a6302bee7c9c89/Lib/ast.py#L1510
----------
components: Library (Lib)
messages: 374269
nosy: alexandre.vassalotti, xtreak
priority: normal
severity: normal
status: open
title: pickle and pickletools cli interface doesn't close input and output file.
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41395>
_______________________________________
More information about the New-bugs-announce
mailing list