[PATCH 06 of 10] py3: add @util.boolclass markers for boolean classes

Yuya Nishihara yuya at tcha.org
Wed May 18 09:55:14 EDT 2016


On Thu, 12 May 2016 01:23:14 +0000, timeless wrote:
> # HG changeset patch
> # User timeless <timeless at mozdev.org>
> # Date 1463009260 0
> #      Wed May 11 23:27:40 2016 +0000
> # Node ID d0b1768012385bb1ceacace2f6c32ee28a29f46e
> # Parent  e670b15b74f80135c28e3ac57b0580ad98b47cb9
> # Available At bb://timeless/mercurial-crew
> #              hg pull bb://timeless/mercurial-crew -r d0b176801238
> py3: add @util.boolclass markers for boolean classes

> --- a/mercurial/context.py	Thu May 12 00:06:19 2016 +0000
> +++ b/mercurial/context.py	Wed May 11 23:27:40 2016 +0000
> @@ -395,6 +395,7 @@
>                   date, extra, editor)
>      return ctx
>  
> + at util.boolclass
>  class changectx(basectx):
>      """A changecontext object makes access to data related to a particular
>      changeset convenient. It represents a read-only context already present in
> @@ -707,6 +708,10 @@
>              # file is missing
>              return False
>  
> +    def __bool__(self):
> +        """Python 3 equivalent of Python 2 __nonzero__"""
> +        return self.__nonzero__()
> +
>      def __str__(self):
>          return "%s@%s" % (self.path(), self._changectx)
>  
> @@ -1180,6 +1185,10 @@
>      def __nonzero__(self):
>          return True
>  
> +    def __bool__(self):
> +        """Python 3 equivalent of Python 2 __nonzero__"""
> +        return self.__nonzero__()
> +
>      def _buildflagfunc(self):
>          # Create a fallback function for getting file flags when the
>          # filesystem doesn't support them
> @@ -1675,6 +1684,10 @@
>      def __nonzero__(self):
>          return True
>  
> +    def __bool__(self):
> +        """Python 3 equivalent of Python 2 __nonzero__"""
> +        return self.__nonzero__()

Just curious why these three don't use @util.boolclass.

Also, if __bool__ is always forwarded to __nonzero__ like these, we don't
need to define __bool__ in all sub classes.


More information about the Mercurial-devel mailing list