Submitter | Jordi Gutiérrez Hermoso |
---|---|
Date | May 21, 2015, 8:30 p.m. |
Message ID | <1afb582cf7f85118a1c4.1432240219@Iris> |
Download | mbox | patch |
Permalink | /patch/9218/ |
State | Accepted |
Headers | show |
Comments
> On May 21, 2015, at 13:30, Jordi Gutiérrez Hermoso <jordigh@octave.org> wrote: > > # HG changeset patch > # User Jordi Gutiérrez Hermoso <jordigh@octave.org> > # Date 1432240086 14400 > # Thu May 21 16:28:06 2015 -0400 > # Node ID 1afb582cf7f85118a1c48c69aaa54625db5afab0 > # Parent bb2f543b48b5290c634cc26c7e61d7c3e9dd8f6e > error: refactor common hint-pattern into a common base class > > I'm about to make another exception class require hints, so third > strike and you refactor. > > diff --git a/mercurial/error.py b/mercurial/error.py > --- a/mercurial/error.py > +++ b/mercurial/error.py > @@ -13,6 +13,11 @@ imports. > > # Do not import anything here, please > > +class HintException(Exception): > + def __init__(self, *args, **kw): > + Exception.__init__(self, *args) > + self.hint = kw.get('hint') > + > class RevlogError(Exception): > pass > > @@ -46,11 +51,9 @@ class CommandError(Exception): > class InterventionRequired(Exception): > """Exception raised when a command requires human intervention.""" > > -class Abort(Exception): > +class Abort(HintException): > """Raised if a command needs to print an error and exit.""" > - def __init__(self, *args, **kw): > - Exception.__init__(self, *args) > - self.hint = kw.get('hint') > + pass Nit: you don't need pass if you have a docstring. Docstrings are part of the AST so they count as a child of an element. > > class HookAbort(Abort): > """raised when a validation hook fails, aborting an operation > @@ -76,10 +79,8 @@ class UnknownIdentifier(ParseError): > self.function = function > self.symbols = symbols > > -class RepoError(Exception): > - def __init__(self, *args, **kw): > - Exception.__init__(self, *args) > - self.hint = kw.get('hint') > +class RepoError(HintException): > + pass > > class RepoLookupError(RepoError): > pass > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel
On Fri, 2015-05-22 at 07:15 -0700, Gregory Szorc wrote: > Nit: you don't need pass if you have a docstring. Docstrings are > part of the AST so they count as a child of an element. I think the "pass" makes it easier to read nonetheless. Do you insist on me omitting?
Patch
diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -13,6 +13,11 @@ imports. # Do not import anything here, please +class HintException(Exception): + def __init__(self, *args, **kw): + Exception.__init__(self, *args) + self.hint = kw.get('hint') + class RevlogError(Exception): pass @@ -46,11 +51,9 @@ class CommandError(Exception): class InterventionRequired(Exception): """Exception raised when a command requires human intervention.""" -class Abort(Exception): +class Abort(HintException): """Raised if a command needs to print an error and exit.""" - def __init__(self, *args, **kw): - Exception.__init__(self, *args) - self.hint = kw.get('hint') + pass class HookAbort(Abort): """raised when a validation hook fails, aborting an operation @@ -76,10 +79,8 @@ class UnknownIdentifier(ParseError): self.function = function self.symbols = symbols -class RepoError(Exception): - def __init__(self, *args, **kw): - Exception.__init__(self, *args) - self.hint = kw.get('hint') +class RepoError(HintException): + pass class RepoLookupError(RepoError): pass