Submitter | Sean Farley |
---|---|
Date | Jan. 15, 2015, 6:58 a.m. |
Message ID | <e2309aabdb6e67fc9eb0.1421305097@laptop.local> |
Download | mbox | patch |
Permalink | /patch/7468/ |
State | Accepted |
Headers | show |
Comments
On 1/14/2015 10:58 PM, Sean Farley wrote: > # HG changeset patch > # User Sean Farley <sean.michael.farley@gmail.com> > # Date 1421293153 28800 > # Wed Jan 14 19:39:13 2015 -0800 > # Node ID e2309aabdb6e67fc9eb0082917b6d79c8798cfbf > # Parent f6070d3a9cb89a50ae3112f7c3d22f4ccc5c4db7 > namespaces: make the constructor into named args > > None of the arguments are truly optional but this makes adding future arguments > more robust and perhaps optional. > > diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py > --- a/mercurial/namespaces.py > +++ b/mercurial/namespaces.py > @@ -118,16 +118,17 @@ class namespace(object): > 'namemap': function that takes a name and returns a list of nodes > 'nodemap': function that takes a node and returns a list of names > > """ > > - def __init__(self, name, templatename, listnames, namemap, nodemap): > + def __init__(self, name, templatename=None, listnames=None, namemap=None, > + nodemap=None): > """create a namespace > > name: the namespace to be registered (in plural form) > + templatename: the name to use for templating > listnames: function to list all names > - templatename: the name to use for templating > namemap: function that inputs a node, output name(s) > nodemap: function that inputs a name, output node(s) > > """ > self.name = name When making parameters optional (from a language perspective), I'd prefer to fail quickly if a required parameter is missing. Eg, abort right away if any of these params is missing (eg, None) rather than assigning them to the namespace and failing at some random place in the future. Does that seem reasonable?
Patch
diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py --- a/mercurial/namespaces.py +++ b/mercurial/namespaces.py @@ -118,16 +118,17 @@ class namespace(object): 'namemap': function that takes a name and returns a list of nodes 'nodemap': function that takes a node and returns a list of names """ - def __init__(self, name, templatename, listnames, namemap, nodemap): + def __init__(self, name, templatename=None, listnames=None, namemap=None, + nodemap=None): """create a namespace name: the namespace to be registered (in plural form) + templatename: the name to use for templating listnames: function to list all names - templatename: the name to use for templating namemap: function that inputs a node, output name(s) nodemap: function that inputs a name, output node(s) """ self.name = name