bpo-34166: Fix warnings in Tools/msgfmt.py. (GH-8367) · python/cpython@a692efe (original) (raw)

Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ def generate():
89 89 7*4, # start of key index
90 90 7*4+len(keys)*8, # start of value index
91 91 0, 0) # size and offset of hash table
92 -output += array.array("i", offsets).tostring()
92 +output += array.array("i", offsets).tobytes()
93 93 output += ids
94 94 output += strs
95 95 return output
@@ -109,7 +109,8 @@ def make(filename, outfile):
109 109 outfile = os.path.splitext(infile)[0] + '.mo'
110 110
111 111 try:
112 -lines = open(infile, 'rb').readlines()
112 +with open(infile, 'rb') as f:
113 +lines = f.readlines()
113 114 except IOError as msg:
114 115 print(msg, file=sys.stderr)
115 116 sys.exit(1)
@@ -199,7 +200,8 @@ def make(filename, outfile):
199 200 output = generate()
200 201
201 202 try:
202 -open(outfile,"wb").write(output)
203 +with open(outfile,"wb") as f:
204 +f.write(output)
203 205 except IOError as msg:
204 206 print(msg, file=sys.stderr)
205 207