Patchwork error: mark HintException as a private base class

login
register
mail settings
Submitter Yuya Nishihara
Date July 8, 2016, 3:50 p.m.
Message ID <1adb7c14f88c38e8570d.1467993039@mimosa>
Download mbox | patch
Permalink /patch/15773/
State Superseded
Headers show

Comments

Yuya Nishihara - July 8, 2016, 3:50 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1451137556 -32400
#      Sat Dec 26 22:45:56 2015 +0900
# Node ID 1adb7c14f88c38e8570d5198141f493547f9acb6
# Parent  b4d117cee636be8a566f56e84d4b351a736a1299
error: mark HintException as a private base class

HintException is unrelated to the hierarchy of errors. It is an implementation
detail whether a class inherits from HintException or not, a sort of "private
inheritance" in C++.

This patch makes sure that client codes never abuse HintException as an
error category.
Matt Mackall - July 8, 2016, 9:33 p.m.
On Sat, 2016-07-09 at 00:50 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1451137556 -32400
> #      Sat Dec 26 22:45:56 2015 +0900
> # Node ID 1adb7c14f88c38e8570d5198141f493547f9acb6
> # Parent  b4d117cee636be8a566f56e84d4b351a736a1299
> error: mark HintException as a private base class
> 
> HintException is unrelated to the hierarchy of errors. It is an implementation
> detail whether a class inherits from HintException or not, a sort of "private
> inheritance" in C++.

Ok.. but do we want to block/discourage external extensions from using this
class to make their own exception types? We could restructure it as a mix-in?

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -15,12 +15,12 @@  from __future__ import absolute_import
 
 # Do not import anything here, please
 
-class HintException(Exception):
+class _HintException(Exception):
     def __init__(self, *args, **kw):
         Exception.__init__(self, *args)
         self.hint = kw.get('hint')
 
-class RevlogError(HintException):
+class RevlogError(_HintException):
     pass
 
 class FilteredIndexError(IndexError):
@@ -50,10 +50,10 @@  class ManifestLookupError(LookupError):
 class CommandError(Exception):
     """Exception raised on errors in parsing the command line."""
 
-class InterventionRequired(HintException):
+class InterventionRequired(_HintException):
     """Exception raised when a command requires human intervention."""
 
-class Abort(HintException):
+class Abort(_HintException):
     """Raised if a command needs to print an error and exit."""
 
 class HookLoadError(Abort):
@@ -87,10 +87,10 @@  class ResponseExpected(Abort):
         from .i18n import _
         Abort.__init__(self, _('response expected'))
 
-class OutOfBandError(HintException):
+class OutOfBandError(_HintException):
     """Exception raised when a remote repo reports failure"""
 
-class ParseError(HintException):
+class ParseError(_HintException):
     """Raised when parsing config files and {rev,file}sets (msg[, pos])"""
 
 class UnknownIdentifier(ParseError):
@@ -102,7 +102,7 @@  class UnknownIdentifier(ParseError):
         self.function = function
         self.symbols = symbols
 
-class RepoError(HintException):
+class RepoError(_HintException):
     pass
 
 class RepoLookupError(RepoError):