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

Get rid of bare "except"s #11668

Open
asmeurer opened this Issue Sep 27, 2016 · 17 comments

Comments

Projects
None yet
@asmeurer
Member

asmeurer commented Sep 27, 2016

It looks like quite a few bare except: and except Exception: lines have crept up throughout the codebase. A few of these are OK (for instance, the ones in runtests.py are there to catch and report exceptions in the tests), but most should be replaced with an explicit exception, or rearranged so that the logic does not require checking for an exception. Even places where you really do want to catch all exceptions, except Exception: is usually better than except:, since the latter also catches things like KeyboardInterrupt and MemoryError, which you generally really do want to raise to the user. I didn't check all the instances in the code, but I can't think of an example where bare except: would be acceptable, excepting the case where there is a raise line in the except block.

I've marked this as easy to fix. It does require a bit of work, however, as you'll need to understand what the code is doing in each instance to know how to fix it (or if it shouldn't be fixed).

@sid21g

This comment has been minimized.

sid21g commented Sep 29, 2016

I wish to take this up.

@krishnacharya

This comment has been minimized.

krishnacharya commented Oct 6, 2016

@sidgupta234 Are you still working on this?

@sid21g

This comment has been minimized.

sid21g commented Oct 7, 2016

Nope, I was waiting for his affirmation, which I didn't get.

@jksuom

This comment has been minimized.

Member

jksuom commented Oct 7, 2016

@sidgupta234 There is no need to wait for an affirmation. You can start working right away on any issue you are interested in.

@ayodejiige

This comment has been minimized.

Contributor

ayodejiige commented Dec 29, 2016

I'm new and would like to take this up if no one is currently working on it.

@moorepants

This comment has been minimized.

Member

moorepants commented Dec 29, 2016

@ayodejiige please do.

@nilabja10201992

This comment has been minimized.

Contributor

nilabja10201992 commented Jan 20, 2017

If it is still open, I would like to work with this?

@OppenheimerAndTheMartians

This comment has been minimized.

OppenheimerAndTheMartians commented Feb 10, 2017

Found some bare excepts... this is my first open source commit here, I don't have write permission to the repo, right? Someone has to review it?

@acz13

This comment has been minimized.

acz13 commented Feb 19, 2017

@OppenheimerAndTheMartians fork the repository, commit there, and pull request back here

@SaiHarsh

This comment has been minimized.

SaiHarsh commented Mar 6, 2017

Is it closed?

@gxyd

This comment has been minimized.

Member

gxyd commented Sep 23, 2017

Announcement: This issue is still open, you can work on it and send in a PR.

@OppenheimerAndTheMartians

This comment has been minimized.

OppenheimerAndTheMartians commented Sep 23, 2017

@SushantGahlot

This comment has been minimized.

SushantGahlot commented Jul 4, 2018

This is still open. Should I go ahead and work on it?

@OppenheimerAndTheMartians

This comment has been minimized.

OppenheimerAndTheMartians commented Jul 5, 2018

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 8, 2018

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 8, 2018

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 8, 2018

@mohitacecode

This comment has been minimized.

mohitacecode commented Dec 14, 2018

    try:
        b = Quaternion.__copysign(b, M[2, 1] - M[1, 2])
        c = Quaternion.__copysign(c, M[0, 2] - M[2, 0])
        d = Quaternion.__copysign(d, M[1, 0] - M[0, 1])

    except Exception:
        pass

    return Quaternion(a, b, c, d)

@staticmethod
def __copysign(x, y):

    # Takes the sign from the second term and sets the sign of the first
    # without altering the magnitude.

    if y == 0:
        return 0

return x if x*y > 0 else -x

do we require try expect here

@asmeurer

This comment has been minimized.

Member

asmeurer commented Dec 14, 2018

Yes, it would likely be better to check for the condition that raises the exception. Or at least catch a more specific exception.

@mohitacecode

This comment has been minimized.

mohitacecode commented Dec 15, 2018

yeah,you are right but i think there is no possiblity of any exception.
please correct me if i am wrong

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