diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-06-28 10:34:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-28 10:34:22 (GMT) |
commit | 04cdeb7a5617c48102f45b965e683b12cdf934f8 (patch) | |
tree | 3bd991eee90cd9d9016d8b13d00b4dfdb689a8c0 /Lib/trace.py | |
parent | cd3c2bdd5d53db7fe1d546543d32000070916552 (diff) | |
download | cpython-04cdeb7a5617c48102f45b965e683b12cdf934f8.zip cpython-04cdeb7a5617c48102f45b965e683b12cdf934f8.tar.gz cpython-04cdeb7a5617c48102f45b965e683b12cdf934f8.tar.bz2 |
bpo-41138: Fix trace CLI for non-UTF-8 files. (GH-21177)
Fix also a resource warning when store counts and module info.
Diffstat (limited to 'Lib/trace.py')
-rwxr-xr-x | Lib/trace.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 52047c3..c505d8b 100755 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -287,8 +287,9 @@ class CoverageResults: if self.outfile: # try and store counts and module info into self.outfile try: - pickle.dump((self.counts, self.calledfuncs, self.callers), - open(self.outfile, 'wb'), 1) + with open(self.outfile, 'wb') as f: + pickle.dump((self.counts, self.calledfuncs, self.callers), + f, 1) except OSError as err: print("Can't save counts files because %s" % err, file=sys.stderr) @@ -715,7 +716,7 @@ def main(): sys.argv = [opts.progname, *opts.arguments] sys.path[0] = os.path.dirname(opts.progname) - with open(opts.progname) as fp: + with open(opts.progname, 'rb') as fp: code = compile(fp.read(), opts.progname, 'exec') # try to emulate __main__ namespace as much as possible globs = { |