[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:
Miss Islington (bot) 2024-01-05 23:37:43 +01:00 committed by GitHub
parent d43f2ad6d9
commit e132751b49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View file

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