mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
gh-85567: Fix resouce warnings in pickle and pickletools CLIs (GH-113618)
Explicitly open and close files instead of using FileType.
This commit is contained in:
parent
3c4e972d6d
commit
bd754b93ca
3 changed files with 30 additions and 13 deletions
|
|
@ -1793,7 +1793,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',
|
||||
|
|
@ -1809,6 +1809,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