Mercurial > hg > mercurial-source
comparison mercurial/registrar.py @ 31387:b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Previous, registering different object with the same name would silently
overwrite the first value with the second one. We now detect the situation and
raise an error. No extension in test or core had the issues.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 12 Dec 2016 13:32:45 +0100 |
parents | 318a24b52eeb |
children | 45761ef1bc93 |
comparison
equal
deleted
inserted
replaced
31386:07025bd744a0 | 31387:b52e8a4f4c0f |
---|---|
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 from . import ( | 10 from . import ( |
11 error, | |
11 pycompat, | 12 pycompat, |
12 util, | 13 util, |
13 ) | 14 ) |
14 | 15 |
15 class _funcregistrarbase(object): | 16 class _funcregistrarbase(object): |
48 return lambda func: self._doregister(func, decl, *args, **kwargs) | 49 return lambda func: self._doregister(func, decl, *args, **kwargs) |
49 | 50 |
50 def _doregister(self, func, decl, *args, **kwargs): | 51 def _doregister(self, func, decl, *args, **kwargs): |
51 name = self._getname(decl) | 52 name = self._getname(decl) |
52 | 53 |
54 if name in self._table: | |
55 msg = 'duplicate registration for name: "%s"' % name | |
56 raise error.ProgrammingError(msg) | |
57 | |
53 if func.__doc__ and not util.safehasattr(func, '_origdoc'): | 58 if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
54 doc = func.__doc__.strip() | 59 doc = func.__doc__.strip() |
55 func._origdoc = doc | 60 func._origdoc = doc |
56 func.__doc__ = self._formatdoc(decl, doc) | 61 func.__doc__ = self._formatdoc(decl, doc) |
57 | 62 |