diff options
author | Bharat123rox <bharatraghunthan9767@gmail.com> | 2019-05-07 23:45:16 +0530 |
---|---|---|
committer | Bharat123rox <bharatraghunthan9767@gmail.com> | 2019-05-07 23:45:16 +0530 |
commit | 38025696d7f268b47d81e215bcf33c50ca1c98c1 (patch) | |
tree | 667fbfc1d3e2fb68ce657ec8fc101921f6b9784d /numpy/linalg | |
parent | dfc0e00eeeb9d3659aa8c06c5d6ea54c5d20742d (diff) | |
download | numpy-38025696d7f268b47d81e215bcf33c50ca1c98c1.tar.gz |
Use with statement to open/close files to fix LGTM alerts
Diffstat (limited to 'numpy/linalg')
-rw-r--r-- | numpy/linalg/lapack_lite/clapack_scrub.py | 5 | ||||
-rw-r--r-- | numpy/linalg/lapack_lite/fortran.py | 21 |
2 files changed, 12 insertions, 14 deletions
diff --git a/numpy/linalg/lapack_lite/clapack_scrub.py b/numpy/linalg/lapack_lite/clapack_scrub.py index e72a39e64..434586113 100644 --- a/numpy/linalg/lapack_lite/clapack_scrub.py +++ b/numpy/linalg/lapack_lite/clapack_scrub.py @@ -294,9 +294,8 @@ def scrubSource(source, nsteps=None, verbose=False): if __name__ == '__main__': filename = sys.argv[1] outfilename = os.path.join(sys.argv[2], os.path.basename(filename)) - fo = open(filename, 'r') - source = fo.read() - fo.close() + with open(filename, 'r') as fo: + source = fo.read() if len(sys.argv) > 3: nsteps = int(sys.argv[3]) diff --git a/numpy/linalg/lapack_lite/fortran.py b/numpy/linalg/lapack_lite/fortran.py index 3b6ac70f0..58c15f032 100644 --- a/numpy/linalg/lapack_lite/fortran.py +++ b/numpy/linalg/lapack_lite/fortran.py @@ -110,15 +110,14 @@ def getDependencies(filename): """For a Fortran source file, return a list of routines declared as EXTERNAL in it. """ - fo = open(filename) - external_pat = re.compile(r'^\s*EXTERNAL\s', re.I) - routines = [] - for lineno, line in fortranSourceLines(fo): - m = external_pat.match(line) - if m: - names = line = line[m.end():].strip().split(',') - names = [n.strip().lower() for n in names] - names = [n for n in names if n] - routines.extend(names) - fo.close() + with open(filename) as fo: + external_pat = re.compile(r'^\s*EXTERNAL\s', re.I) + routines = [] + for lineno, line in fortranSourceLines(fo): + m = external_pat.match(line) + if m: + names = line = line[m.end():].strip().split(',') + names = [n.strip().lower() for n in names] + names = [n for n in names if n] + routines.extend(names) return routines |