[PATCH 2 of 5] registrar: introduce funcregistrarbase to replace funcregistrar

Yuya Nishihara yuya at tcha.org
Thu Jan 7 08:46:02 CST 2016


On Tue, 05 Jan 2016 20:48:35 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1451994203 -32400
> #      Tue Jan 05 20:43:23 2016 +0900
> # Node ID de07b46cc5de1baa86d40492941fd56c849311c3
> # Parent  e526fa5df73b5263d164bd339251481050755720
> registrar: introduce funcregistrarbase to replace funcregistrar

> 'extrasetup()' is invoked with *args and **kwargs arguments in
> 'doregister()', but it is defined without them, because this can
> reject unknown optional argument at decoration easily, if derived
> class doesn't override 'extrasetup()' with any optional arguments.

Neat.

> +class funcregistrarbase(object):

Let's mark this class and its internal callbacks as private to make sure
that the derived classes should be defined in the registrar.

> +    def __init__(self):
> +        self.table = {}

Perhaps core modules would want to pass a table.

  # revset.py
  predicate = registrar.revsetpredicate(symbols)

If there's no revset.safesymbols, we can do it.

> +    def doregister(self, func, decl, *args, **kwargs):
> +        name = self.getname(decl)
> +
> +        if func.__doc__ and not util.safehasattr(func, '_origdoc'):
> +            doc = func.__doc__.strip()
> +            func._origdoc = doc
> +            if callable(self.formatdoc):
> +                func.__doc__ = self.formatdoc(decl, doc)
> +            else:
> +                # convenient shortcut for simple format
> +                func.__doc__ = self.formatdoc % (decl, doc)

I'm a little shocked that formatdoc() is overloaded as a format string.
I would rather do

  def _formatdoc(self, decl, doc):
      return self._doctemplate % (decl, doc)  # override me if needed

> +    def parsefuncdecl(self, decl):
> +        """Parse function declaration and return the name of function in it
> +        """
> +        i = decl.find('(')
> +        if i > 0:
> +            return decl[:i]
> +        else:
> +            return decl

Is it intentional that i == 0 isn't counted as a function declaration?
"()" is invalid name anyway, but I'm just curious why you've chosen i > 0.


More information about the Mercurial-devel mailing list