mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-85567: Fix resouce warnings in pickle and pickletools CLIs (GH-113618) (GH-113758)
Explicitly open and close files instead of using FileType.
(cherry picked from commit bd754b93ca
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
d43f2ad6d9
commit
e132751b49
3 changed files with 30 additions and 13 deletions
|
@ -1791,7 +1791,7 @@ if __name__ == "__main__":
|
|||
parser = argparse.ArgumentParser(
|
||||
description='display contents of the pickle files')
|
||||
parser.add_argument(
|
||||
'pickle_file', type=argparse.FileType('br'),
|
||||
'pickle_file',
|
||||
nargs='*', help='the pickle file')
|
||||
parser.add_argument(
|
||||
'-t', '--test', action='store_true',
|
||||
|
@ -1807,6 +1807,10 @@ if __name__ == "__main__":
|
|||
parser.print_help()
|
||||
else:
|
||||
import pprint
|
||||
for f in args.pickle_file:
|
||||
obj = load(f)
|
||||
for fn in args.pickle_file:
|
||||
if fn == '-':
|
||||
obj = load(sys.stdin.buffer)
|
||||
else:
|
||||
with open(fn, 'rb') as f:
|
||||
obj = load(f)
|
||||
pprint.pprint(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue