[PATCH] match: make 'always' and 'exact' functions, not classes

Martin von Zweigbergk martinvonz at google.com
Sun Dec 14 00:28:26 CST 2014


I was reminded of this old patch when I re-read the CodingStyle page, which
says "Think twice about using classes, functions are almost always smaller
and simpler".

On Sat Dec 13 2014 at 10:27:04 PM Martin von Zweigbergk <
martinvonz at google.com> wrote:

> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz at google.com>
> # Date 1414907809 25200
> #      Sat Nov 01 22:56:49 2014 -0700
> # Node ID 48f76f52ab6eea77d1609ab6e17a7788ad0bf6f9
> # Parent  495bc1b65d25872324a0220354f048b220304bd1
> match: make 'always' and 'exact' functions, not classes
>
> There is no reason for classes 'always' and 'exact' not to be just
> functions that return instances the plain 'match' class.
>
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -156,13 +156,11 @@
>          - optimization might be possible and necessary.'''
>          return self._always
>
> -class exact(match):
> -    def __init__(self, root, cwd, files):
> -        match.__init__(self, root, cwd, files, exact=True)
> +def exact(root, cwd, files):
> +    return match(root, cwd, files, exact=True)
>
> -class always(match):
> -    def __init__(self, root, cwd):
> -        match.__init__(self, root, cwd, [])
> +def always(root, cwd):
> +    return match(root, cwd, [])
>
>  class narrowmatcher(match):
>      """Adapt a matcher to work on a subdirectory only.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20141214/d0af3356/attachment.html>


More information about the Mercurial-devel mailing list