[ovs-dev] [PATCH] python/ovs/db/types: Fix English grammar for enums with one member.

Reid Price rprice at nicira.com
Fri Feb 1 23:49:11 UTC 2013


Looks good.  I assume there is no way to have no literals?

For what it's worth,

   english = 'one of %s, %s, or %s' % (literals[0],
                                       ', '.join(literals[1:-1]),
                                       literals[-1])

could also be written as

   english = 'one of %s, or %s' % (', '.join(literals[:-1]),
                                   literals[-1])

or you could even replace the whole thing with

   literals[-1] = 'or %s' % literals[-1]
   prefix = {1: 'must be', 2: 'either'}.get(len(literals), 'one of')
   english = "%s %s" % (prefix, ', '.join(literals))

which does leave you with the wart "either a, or b", and is definitely less
obviously correct =)

  -Reid

On Fri, Feb 1, 2013 at 2:52 PM, Ben Pfaff <blp at nicira.com> wrote:
> Before this change, enums that have one member were formatted as, e.g.:
>     "one of xyzzy, , or "
> This changes them to be formatted as:
>     "must be xyzzy"
> which makes much more sense.
>
> (An enum with one member may make some sense if you are trying to leave
> the possibility for future expansion.)
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> This is a repost of a patch originally posted Dec. 20, 2012.
>
>  python/ovs/db/types.py |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py
> index 5865acd..bd1c259 100644
> --- a/python/ovs/db/types.py
> +++ b/python/ovs/db/types.py
> @@ -287,7 +287,9 @@ class BaseType(object):
>          if self.enum:
>              literals = [value.toEnglish(escapeLiteral)
>                          for value in self.enum.values]
> -            if len(literals) == 2:
> +            if len(literals) == 1:
> +                english = 'must be %s' % (literals[0])
> +            elif len(literals) == 2:
>                  english = 'either %s or %s' % (literals[0], literals[1])
>              else:
>                  english = 'one of %s, %s, or %s' % (literals[0],
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130201/1f328c23/attachment-0003.html>


More information about the dev mailing list