[MERGE] Rule-based preferences (EOL part 1 of 3)

John Arbash Meinel john at arbash-meinel.com
Wed Jun 25 15:15:15 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ian Clatworthy wrote:
| John Arbash Meinel wrote:
|> John Arbash Meinel has voted tweak.
|
|> +    def get_items(self, path, names=None):
|> +        """Return the preferences for a path as a sequence of
|> name,value tuples.
|> +
|> +        :param path: tree relative path
|> +        :param names: the list of preferences to lookup - None for all
|> +        :return: None if no rule matched, otherwise a sequence of
|> name,value
|> +          tuples. If names is not None, the sequence is the same
length as
|> +          names, tuple order matches the order in names, and undefined
|> +          preferences are given the value None.
|> +        """
|> +        raise NotImplementedError(self.get_items)
|>
|> ^- The api here seems heavily dependent on whether names is supplied or
|> not. (If you supply it, you always get return values, if you don't you
|> sometimes get a sequence, sometimes get None.)
|
| Hmm, not really. As the text says "None if no rule matched".
| I think the API design is OK - it's exactly what *I* want/need. :-)
| I'm happy to improve the docstring if you can suggest some better text.

I'm not very fond of apis changing their return value in random ways
based on parameters. You have 3 different return objects, and while I
realize it fits what you need, you might consider having different APIs
rather than a dual purpose one.

get_items(path) => None
get_items(path) => ['name', 'name', 'name']

Why not

get_items(path) => [] ??

As the first question. And why not have:

get_named_items(path, names) => ['value', None, None, 'value']

Instead of an optional parameter that changes the return value?

|
|> +    def test_get_items_from_extension_match(self):
|> +        rs = self.make_searcher(["[*.txt]", "foo=bar", "a=True"])
|>
|> ^- Shouldn't these lines have '\n' at the end of them?
|> Even better, have it take "text" and then do the splitting yourself
|> before handing it to _IniBasedRulesSearcher. I think it would be a lot
|> easier for humans to understand than trying to follow the nested [] and
|> quote characters.
|
| I'm yet to do this but I'm happy to once the namespace keyword is agreed
| (and hence the text is stable).
|
| Ian C.

Sure

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhiUvMACgkQJdeBCYSNAAOWnQCgng6zInsEsh/roirrkDnvGYot
6xYAnim05onP4IVXVlCUb3rp9E2B9YRN
=OYyn
-----END PGP SIGNATURE-----



More information about the bazaar mailing list