Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
converted assert into exception#3060
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
montefra commentedMay 13, 2014
in |
WeatherGod commentedMay 13, 2014
I like this post about assertions: https://mail.python.org/pipermail/python-list/2013-November/660401.html I wouldn't go hog-wild in converting the asserts into exceptions, but |
montefra commentedMay 13, 2014
Thanks for the link, I'll read it more carefully tomorrow. I agree about not going wild. Anyway these two points at the end
convinced me even more that my PR make sense |
WeatherGod commentedMay 13, 2014
Indeed. To highlight two particular paragraphs that I find illuminating: On Tue, May 13, 2014 at 5:07 PM, Francesco Montesano <
|
tacaswell commentedMay 17, 2014
I don't really want to do this for 1.4.0, labeled for 1.4.x |
lib/matplotlib/figure.py Outdated
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 quite rarely construct my own exception types, the built-in exceptions are pretty comprehensive. In this case, a ValueError would be just as valuable IMHO (https://docs.python.org/2/library/exceptions.html#exceptions.ValueError). Thoughts?
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.
fine with me.
montefra commentedMay 20, 2014
I'll try to get back with further commits later this week or next one. |
montefra commentedMay 28, 2014
Before I embark myself into |
montefra commentedMay 28, 2014
ps: before anyone asks or complain. I'm going to run the test suite and adjust it if needed once I'm done with removing the asserts |
tacaswell commentedMay 29, 2014
I would avoid touching the backends just yet, they are on my list of things to re-factor as soon as 1.4 gets out (see#2624 ). |
montefra commentedMay 30, 2014
I've left alone a few asserts on private functions after checking that no user input is directly passed to them. |
montefra commentedJun 3, 2014
this line looks like a but to me. Shouldn't it be If it's a bug, I'll fix it here Besides: I didn't dare to touch |
tacaswell commentedJun 3, 2014
Please make a separate PR for that bug. |
tacaswell commentedJun 3, 2014
Also, I think that entire block of functions are candidates to be removed from the library. I have never looked at them before, but scanning them they look like they are replicating much of the functionality that |
montefra commentedJun 3, 2014
@tacaswell: I'll do a separate PR. |
montefra commentedJun 12, 2014
I'm waiting Travis answer in case I need to fix any problem. And I have a question about testing.
If I It is correct? |
montefra commentedJun 18, 2014
I've installed matplotlib as The failing tests are:
Now I run |
montefra commentedJun 18, 2014
With python3 I get three extra errors:
The traceback is always the same (except for the actual attribute name) |
tacaswell commentedFeb 7, 2015
At a minimum this needs a re-base. @pelson@mdboom@efiring Thoughts? I think I am in favor of switching asserts in public facing function into exceptions so we can provide more meaningful error messages/make sane error handling possible. I think private functions should keep using assert as they can in principle be suppressed for efficiency reasons. |
mdboom commentedFeb 9, 2015
@tacaswell: I agree with that assert vs. exception policy.@montefra: Sorry this has sat here so long. It would be nice to rebase this so we can merge. |
efiring commentedFeb 9, 2015
@tacaswell: Yes, I agree also. |
montefra commentedFeb 10, 2015
At the moment I'm travelling, so I don't know when I'll do it. For sure I can rebase, test and commit within a week and a half. Is there any hurry? |
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.
or should beand
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.
see above
tacaswell commentedMar 16, 2015
@montefra I left you a bunch of style-related comment and a few places where I was confused by the logic. Thank you for doing this! |
montefra commentedMar 16, 2015
@tacaswell it seems that we now agree 👍 Should I rebase? |
lib/matplotlib/table.py Outdated
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.
This formatting does not work with python 2.6, you have to explicitly put in either index or kwargs.
tacaswell commentedMar 22, 2015
This is getting really close! Just a few minor issues (one class of 2.6 compatibility one class of style consistency). Thank you so much for working on this! |
tacaswell commentedMar 22, 2015
Please @ ping me when this is updated. |
montefra commentedMar 22, 2015
@tacaswell: on top of your comments, I went through all my modifications to make the whole thing more consistent. ps: I've found a few more |
tacaswell commentedMar 22, 2015
Awesome. A PR to clean up the format calls else where would be appreciated. |
MNT : converted assert into exceptionConvert input-validation assertions to raise Exceptions (mostly ValueError) instead.
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.
whoops! looks like we forgot to add araise here. This is fixed in#4458
A few days I ago I was experimenting for a possible answer tothis question. While trying
I stumbled into an
AssertionErrorwithout any explanation (I had to get the doc ofadd_axes).My understanding is that
assertshould be reserved for debugging, not to throw errors if the user give a wrong parameter. So I've converted them to exception.I've also noticed that
assertis used all over the places. If there are no strong opinions in the next weeks I'll to go through the code and convert them to exceptions.