Submitter | Martin von Zweigbergk |
---|---|
Date | Dec. 14, 2014, 6:27 a.m. |
Message ID | <48f76f52ab6eea77d160.1418538420@martinvonz.mtv.corp.google.com> |
Download | mbox | patch |
Permalink | /patch/7083/ |
State | Accepted |
Delegated to: | Pierre-Yves David |
Headers | show |
Comments
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@google.com> wrote: > # HG changeset patch > # User Martin von Zweigbergk <martinvonz@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. >
On 12/13/2014 10:27 PM, Martin von Zweigbergk wrote: > # HG changeset patch > # User Martin von Zweigbergk <martinvonz@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 Pushed to the clowncopter, thanks.
Patch
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.