subclass Exception replace BaseException #997

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@s7v7nislands
Contributor

All user-defined exceptions should also be derived from Exception
https://docs.python.org/3/library/exceptions.html?highlight=baseexception#base-classes

@berkerpeksag
Collaborator

I think the BaseException usage was intentional: 8d453fb However, I'd at least change ConfigError to be derived from Exception.

@s7v7nislands
Contributor

@berkerpeksag what's the reason change in
8d453fb
can you explain it?

@berkerpeksag
Collaborator

Well, I thought it was for to not catch HaltServer in gunicorn/arbiter.py explicitly, but I was wrong: https://github.com/benoitc/gunicorn/blob/master/gunicorn/arbiter.py#L200 Unless there is a reason to use BaseException, the patch LGTM.

@benoitc
Owner
benoitc commented Mar 21, 2015

If I remember well the reason was to make sure it is not accidentally caught by code. There was also something in python 3 vs python2 but I can't recollect right now.

@benoitc
Owner
benoitc commented Jul 7, 2015

So to be clear BaseException is used there in the same way it's used on low level modules in python. I would keep it for HaltServer then. Config I don't know but also don't really care about it. Does someone else think that change is needed?

@tilgovi
Collaborator
tilgovi commented Jul 7, 2015

This is the typical style. We should change it to be Exception unless there's a reason it won't work.

@berkerpeksag
Collaborator

If I remember well the reason was to make sure it is not accidentally caught by code.

Actually, this is a good reason. +1 for keeping HaltServer as it is and changing other instances to inherit from Exception instead of BaseException.

@tilgovi
Collaborator
tilgovi commented Oct 8, 2015

👍 @s7v7nislands if you want to update the PR we can merge just the ConfigError change.

@tilgovi
Collaborator
tilgovi commented Oct 8, 2015

Maybe add a comment to the HaltServer that says that we don't inherit from Exception to avoid having it be caught by application code.

@benoitc benoitc added a commit that closed this pull request Oct 8, 2015
@benoitc inherit from Exception where it needs to be
inherit from Exception where it needs to be and document why we use BaseException.

fix #997
44ac4e4
@benoitc benoitc closed this in 44ac4e4 Oct 8, 2015
@benoitc
Owner
benoitc commented Oct 8, 2015

@tilgovi good idea. just did it :)

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