[PATCH 1 of 4] error: refactor common hint-pattern into a common base class
Gregory Szorc
gregory.szorc at gmail.com
Fri May 22 14:15:47 UTC 2015
> On May 21, 2015, at 13:30, Jordi Gutiérrez Hermoso <jordigh at octave.org> wrote:
>
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh at 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 at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list