This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pickle and pickletools cli interface doesn't close input and output file.
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Amir, achhina, alexandre.vassalotti, corona10, python-dev, s.williams-wynn, serhiy.storchaka, xtreak
Priority: normal Keywords: easy, patch

Created on 2020-07-25 14:12 by xtreak, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 21676 closed python-dev, 2020-07-29 17:19
PR 21702 open Amir, 2020-08-02 07:27
PR 32257 open achhina, 2022-04-02 19:41
Messages (2)
msg374269 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-07-25 14:12
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
msg416776 - (view) Author: Adam (achhina) * Date: 2022-04-05 13:05
Hi,

First-time contributor here, I've made a patch in follow-up to the discussions that happened in Amir's patch in regards to this. I'd appreciate it if someone would be able to take a look and review it! 

https://github.com/python/cpython/pull/32257
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85567
2022-04-05 13:05:47achhinasetmessages: + msg416776
2022-04-02 19:41:53achhinasetnosy: + achhina
pull_requests: + pull_request30326
2020-08-02 07:27:29Amirsetnosy: + Amir
pull_requests: + pull_request20845
2020-07-30 08:57:10s.williams-wynnsetnosy: + s.williams-wynn
2020-07-29 17:19:10python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request20821
stage: patch review
2020-07-28 07:55:02serhiy.storchakasetkeywords: + easy
2020-07-28 07:43:13corona10setnosy: + corona10
2020-07-25 14:43:35serhiy.storchakasetnosy: + serhiy.storchaka
2020-07-25 14:12:10xtreakcreate