Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Added Chain exceptions where appropriate #18400

Merged
merged 9 commits into from
Mar 18, 2021

Conversation

abhayaman669
Copy link
Contributor

This PR is related to #15986
Thank you.

Base automatically changed from master to main March 4, 2021 02:05
@@ -595,7 +595,7 @@ def _read_array_header(fp, version):
d = safe_eval(header)
except SyntaxError as e:
msg = "Cannot parse header: {!r}\nException: {!r}"
raise ValueError(msg.format(header, e))
raise ValueError(msg.format(header, e)) from None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should probably be from e

@@ -616,7 +616,7 @@ def _read_array_header(fp, version):
dtype = descr_to_dtype(d['descr'])
except TypeError:
msg = "descr is not a valid dtype descriptor: {!r}"
raise ValueError(msg.format(d['descr']))
raise ValueError(msg.format(d['descr'])) from None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from e would be better here too

@@ -657,7 +657,7 @@ def openfile(fname):
try:
f = open(fname)
except IOError:
raise IOError(f"No such file: '{fname}'")
raise IOError(f"No such file: '{fname}'") from None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from e again; otherwise if the open fails for permission reasons, all we'll see is "no such file"

@abhayaman669 abhayaman669 force-pushed the chain-exceptions-where-appropriate-1 branch from c09c46f to 0ca74f5 Compare March 13, 2021 10:15
@abhayaman669
Copy link
Contributor Author

Hi @eric-wieser , I've update the PR.
Thanks.

Comment on lines 597 to 598
msg = "Cannot parse header: {!r}\nException: {!r}"
raise ValueError(msg.format(header, e))
raise ValueError(msg.format(header, e)) from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one should remove the Exception: {!r} bit, as otherwise the exception appears twice. The one that appears to to from e appears in more detail, so we should remove the other one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll remove it and update the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated PR for this :)

numpy/lib/format.py Outdated Show resolved Hide resolved
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@charris
Copy link
Member

charris commented Mar 17, 2021

@eric-wieser Ping.

@charris charris merged commit cb71c43 into numpy:main Mar 18, 2021
@charris
Copy link
Member

charris commented Mar 18, 2021

Thanks @abhayaman669 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants