Submitter | phabricator |
---|---|
Date | Aug. 31, 2019, 5:35 p.m. |
Message ID | <differential-rev-PHID-DREV-qcfpepu7n4n6on3w7gmj-req@mercurial-scm.org> |
Download | mbox | patch |
Permalink | /patch/41447/ |
State | Superseded |
Headers | show |
Comments
Patch
diff --git a/mercurial/statprof.py b/mercurial/statprof.py --- a/mercurial/statprof.py +++ b/mercurial/statprof.py @@ -236,18 +236,14 @@ def getsource(self, length): if self.source is None: lineno = self.lineno - 1 - fp = None try: - fp = open(self.path, 'rb') - for i, line in enumerate(fp): - if i == lineno: - self.source = line.strip() - break + with open(self.path, 'rb') as fp: + for i, line in enumerate(fp): + if i == lineno: + self.source = line.strip() + break except: pass - finally: - if fp: - fp.close() if self.source is None: self.source = ''