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
Add better error message when trying to get edge that is not present #7245
Add better error message when trying to get edge that is not present #7245
Conversation
82211cf
to
4a29abd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better exception message would be an improvement, though changing the exception type would be a backwards-incompatible change. One possible compromise would be to re-raise the KeyError
with the new exception message (i.e. replace the nx.NetworkXError
in this PR with KeyError
).
This would give the better exception message while preserving back compat - WDYT?
Or, if it is important that all exceptions that are emitted from NetworkX is of type class NetworkXKeyError(KeyError, nx.NetworkXError)
pass |
IMO this isn't important, but perhaps others have more informed opinions. I'd prefer to stick with builtin exceptions where possible, and I think KeyError works nicely for this case (NX graphs are "dicts all the way down" after all). I can be persuaded otherwise though; the only thing I'm -1 on is a backward-incompatible change in the exception type! |
c956934
to
3fc2676
Compare
3fc2676
to
77aa315
Compare
Sounds good. I changed it to re-raise |
Co-authored-by: Dan Schult <dschult@colgate.edu>
cb91308
to
fbf0980
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the liberty of pushing a few changes (mostly cosmetic) and tried to simplify the match=
logic a bit by making more liberal use of wildcards.
Otherwise this LGTM, thanks @finsberg !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good... Thanks!
…etworkx#7245) * Add better error message when trying to get edge that is not present * reraise KeyError instead for NetworkXError * Update networkx/classes/tests/test_reportviews.py Co-authored-by: Dan Schult <dschult@colgate.edu> * Excape regex pattern * Minor updates, simplify exception and tests. --------- Co-authored-by: Dan Schult <dschult@colgate.edu> Co-authored-by: Ross Barnowski <rossbar@caltech.edu>
When trying to get an edge that is not present in the graph it will give a
KeyError
, but I think it would be better to have an error message saying that the edge is not present in the graph.