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, 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 2020-08-02 07:27 by Amir.

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
Messages (1)
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
History
Date User Action Args
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