[PATCH 6 of 8] import-checker: handle ast.parse SyntaxErrors

Gregory Szorc gregory.szorc at gmail.com
Sun Apr 3 18:12:16 UTC 2016


On Thu, Mar 31, 2016 at 7:34 AM, Yuya Nishihara <yuya at tcha.org> wrote:

> On Wed, 30 Mar 2016 04:24:06 -0500, timeless wrote:
> > # HG changeset patch
> > # User timeless <timeless at mozdev.org>
> > # Date 1459325470 0
> > #      Wed Mar 30 08:11:10 2016 +0000
> > # Node ID d8be8db8119d2d716ad9ddaaaa077cf278f6273c
> > # Parent  54b962661f75e4a55c213c0eeb30f5d6024f7dbe
> > import-checker: handle ast.parse SyntaxErrors
> >
> > diff --git a/contrib/import-checker.py b/contrib/import-checker.py
> > --- a/contrib/import-checker.py
> > +++ b/contrib/import-checker.py
> > @@ -233,6 +233,13 @@
> >
> >  stdlib_modules = set(list_stdlib_modules())
> >
> > +def parse(source):
> > +    """Wrapper around ast.parse()"""
> > +    try:
> > +        return ast.parse(source)
> > +    except SyntaxError:
> > +        return ast.parse("'SyntaxError'")
>
> Doesn't it just bury a SyntaxError? I think it should be reported as an
> error like other messages.
>
>
Yes, but this patch does get us import-checker.py support for Python 3
without having to fix all syntax errors on Python 3 first.

We may want to establish a standalone test to verify ast parsing on all .py
files (if we don't have one already). test-check-py3-compat.t does this,
but only for Python 3. It seems like a useful test to have. I'm fine with
only 1 test reporting ast/import errors, especially on Python 3 (otherwise
we'd have to update multiple tests when addressing Python 3 compat).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20160403/ffeaa262/attachment.html>


More information about the Mercurial-devel mailing list