diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2019-03-03 09:39:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-03 09:39:36 -0700 |
commit | 4056847a275117a97b47fb1f88aafa2b58982d93 (patch) | |
tree | 96c68a70d7f82209bb62e840fa81ec8451e5cf03 | |
parent | 332c6b11c474e9823e968a85c904f2026fb204c0 (diff) | |
parent | ae423c3de5e0768df7ff7a4e2a09f17a9531698d (diff) | |
download | numpy-4056847a275117a97b47fb1f88aafa2b58982d93.tar.gz |
Merge pull request #13077 from eric-wieser/fix-%-format
BUG: Fix errors in string formatting while producing an error
-rw-r--r-- | numpy/lib/format.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 7648be615..4da1022ca 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -524,7 +524,7 @@ def _read_array_header(fp, version): elif version == (2, 0): hlength_type = '<I' else: - raise ValueError("Invalid version %r" % version) + raise ValueError("Invalid version {!r}".format(version)) hlength_str = _read_bytes(fp, struct.calcsize(hlength_type), "array header length") header_length = struct.unpack(hlength_type, hlength_str)[0] @@ -540,29 +540,29 @@ def _read_array_header(fp, version): try: d = safe_eval(header) except SyntaxError as e: - msg = "Cannot parse header: %r\nException: %r" - raise ValueError(msg % (header, e)) + msg = "Cannot parse header: {!r}\nException: {!r}" + raise ValueError(msg.format(header, e)) if not isinstance(d, dict): - msg = "Header is not a dictionary: %r" - raise ValueError(msg % d) + msg = "Header is not a dictionary: {!r}" + raise ValueError(msg.format(d)) keys = sorted(d.keys()) if keys != ['descr', 'fortran_order', 'shape']: - msg = "Header does not contain the correct keys: %r" - raise ValueError(msg % (keys,)) + msg = "Header does not contain the correct keys: {!r}" + raise ValueError(msg.format(keys)) # Sanity-check the values. if (not isinstance(d['shape'], tuple) or not numpy.all([isinstance(x, (int, long)) for x in d['shape']])): - msg = "shape is not valid: %r" - raise ValueError(msg % (d['shape'],)) + msg = "shape is not valid: {!r}" + raise ValueError(msg.format(d['shape'])) if not isinstance(d['fortran_order'], bool): - msg = "fortran_order is not a valid bool: %r" - raise ValueError(msg % (d['fortran_order'],)) + msg = "fortran_order is not a valid bool: {!r}" + raise ValueError(msg.format(d['fortran_order'])) try: dtype = descr_to_dtype(d['descr']) except TypeError as e: - msg = "descr is not a valid dtype descriptor: %r" - raise ValueError(msg % (d['descr'],)) + msg = "descr is not a valid dtype descriptor: {!r}" + raise ValueError(msg.format(d['descr'])) return d['shape'], d['fortran_order'], dtype |