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:
Serhiy Storchaka 2024-01-06 00:12:34 +02:00 committed by GitHub
parent 3c4e972d6d
commit bd754b93ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View file

@ -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)