summaryrefslogtreecommitdiff
path: root/numpy/lib/format.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-06-04 23:05:08 -0700
committerEric Wieser <wieser.eric@gmail.com>2019-06-04 23:05:08 -0700
commit8826e0ffc2c5286572dff1d490bcda88a6f7cd64 (patch)
treefa7ddf7d7831efe67b4dee013d4def04c2beffeb /numpy/lib/format.py
parent40ada70d9efc903097b2ff3f968c23a7e2f14296 (diff)
downloadnumpy-8826e0ffc2c5286572dff1d490bcda88a6f7cd64.tar.gz
MAINT: Use a with statement instead of try / finally
All of this code was already correct, this just tidies it a little
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r--numpy/lib/format.py10
1 files changed, 2 insertions, 8 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index cd8700051..f5f3b28d3 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -841,16 +841,12 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None,
shape=shape,
)
# If we got here, then it should be safe to create the file.
- fp = open(os_fspath(filename), mode+'b')
- try:
+ with open(os_fspath(filename), mode+'b') as fp:
_write_array_header(fp, d, version)
offset = fp.tell()
- finally:
- fp.close()
else:
# Read the header of the file first.
- fp = open(os_fspath(filename), 'rb')
- try:
+ with open(os_fspath(filename), 'rb') as fp:
version = read_magic(fp)
_check_version(version)
@@ -859,8 +855,6 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None,
msg = "Array can't be memory-mapped: Python objects in dtype."
raise ValueError(msg)
offset = fp.tell()
- finally:
- fp.close()
if fortran_order:
order = 'F'