Patchwork [01,of,22] check-code: allow "from mercurial.(pure|cext) import x as y"

login
register
mail settings
Submitter Jun Wu
Date June 4, 2017, 11:59 p.m.
Message ID <5c3500de0a229d8aa080.1496620753@x1c>
Download mbox | patch
Permalink /patch/21197/
State Accepted
Headers show

Comments

Jun Wu - June 4, 2017, 11:59 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1496444920 25200
#      Fri Jun 02 16:08:40 2017 -0700
# Node ID 5c3500de0a229d8aa08058bccec531d8a85b90d9
# Parent  783394c0c97807e83daad9da561179bd0719e159
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5c3500de0a22
check-code: allow "from mercurial.(pure|cext) import x as y"

We want to forbid things like "from mercurial.cext import parsers". But
sometimes it's useful to import a package directly. When that happens, the
code probably wants an alternative name for the module using "as ...".

This pattern will be used by the next patch.
Augie Fackler - June 5, 2017, 6:44 p.m.
On Sun, Jun 04, 2017 at 04:59:13PM -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1496444920 25200
> #      Fri Jun 02 16:08:40 2017 -0700
> # Node ID 5c3500de0a229d8aa08058bccec531d8a85b90d9
> # Parent  783394c0c97807e83daad9da561179bd0719e159
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5c3500de0a22
> check-code: allow "from mercurial.(pure|cext) import x as y"

I don't see in the series where this ended up getting used. Did I just miss it?

>
> We want to forbid things like "from mercurial.cext import parsers". But
> sometimes it's useful to import a package directly. When that happens, the
> code probably wants an alternative name for the module using "as ...".
>
> This pattern will be used by the next patch.
>
> diff --git a/contrib/check-code.py b/contrib/check-code.py
> --- a/contrib/check-code.py
> +++ b/contrib/check-code.py
> @@ -342,5 +342,5 @@ pypats = [
>      (r'^import BaseHTTPServer', "use util.httpserver instead"),
>      (r'^(from|import) mercurial\.(cext|pure|cffi)',
> -     "use mercurial.policy.importmod instead"),
> +     "use mercurial.policy.importmod instead", r' as \S*$'),
>      (r'\.next\(\)', "don't use .next(), use next(...)"),
>      (r'([a-z]*).revision\(\1\.node\(',
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Jun Wu - June 5, 2017, 6:47 p.m.
Excerpts from Augie Fackler's message of 2017-06-05 14:44:34 -0400:
> > check-code: allow "from mercurial.(pure|cext) import x as y"
> 
> I don't see in the series where this ended up getting used. Did I just miss it?

The test uses pure to reuse some struct.Struct.unpack to dump the file in a
human-friendly format.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -342,5 +342,5 @@  pypats = [
     (r'^import BaseHTTPServer', "use util.httpserver instead"),
     (r'^(from|import) mercurial\.(cext|pure|cffi)',
-     "use mercurial.policy.importmod instead"),
+     "use mercurial.policy.importmod instead", r' as \S*$'),
     (r'\.next\(\)', "don't use .next(), use next(...)"),
     (r'([a-z]*).revision\(\1\.node\(',