New submission from Karthikeyan Singaravelan <tir.kar...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue41395> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com