On Thu, 13 Oct 2016 10:22:08 +0100, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpiet...@fb.com>
> # Date 1476350485 -3600
> #      Thu Oct 13 10:21:25 2016 +0100
> # Node ID 36607cf1bbd9fd4d99b607f927bc807fcc48d0ea
> # Parent  733fb9f7bc92c694ba6bededaeb93206528c0bcd
> py3: refactor token parsing to handle call args properly

Nice, but one nit.

> +        def _findargnofcall(n):
> +            """Find arg n of a call expression (start at 0)
> +
> +            Returns index of the first token of that argument, or None if
> +            there is not that many arguments.
> +
> +            Assumes that token[i + 1] is '('.
> +
> +            """
> +            j = i + 2
> +            nested = 0
> +            try:
> +                while True:
> +                    if _isop(j, ')', ']', '}'):
> +                        # end of call, tuple, subscription or dict / set
> +                        nested -= 1
> +                        if nested < 0:
> +                            return None
> +                    elif n == 0:
> +                        # this is the starting position of arg
> +                        return j
> +                    elif _isop(j, '(', '[', '{'):
> +                        nested += 1
> +                    elif _isop(j, ',') and nested == 0:
> +                        n -= 1
> +                    j += 1
> +            except IndexError:
> +                return None

This loop would never stop if malformed tokens were provided. I guess you
had a working version in which _isop() could raise IndexError.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to