[PATCH 2 of 8] localrepo: use absolute import

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue May 26 00:41:28 CDT 2015



On 05/25/2015 10:15 PM, Gregory Szorc wrote:
> On Mon, May 25, 2015 at 9:56 PM, Pierre-Yves David
> <pierre-yves.david at ens-lyon.org <mailto:pierre-yves.david at ens-lyon.org>>
> wrote:
>
>
>
>     On 05/25/2015 12:23 PM, Gregory Szorc wrote:
>
>         # HG changeset patch
>         # User Gregory Szorc <gregory.szorc at gmail.com
>         <mailto:gregory.szorc at gmail.com>>
>         # Date 1432580350 25200
>         #      Mon May 25 11:59:10 2015 -0700
>         # Node ID c2b845cda536ef0abc665befb19319f53bb6216e
>         # Parent  f085ecda3b0e11341ecc119683d5fc47038540d4
>         localrepo: use absolute import
>
>         Python 3 changes the behavior of "import" to only be absolute.
>         In Python
>         2.x "import foo" could import a top-level package or a module
>         from the
>         current package. This resulted in ambiguity when the name of a
>         module
>         conflicted with the name of a package. It also resulted in a slight
>         performance overhead. Since the name of a module could be ambiguous,
>         Python would stat() multiple paths until a module was located. With
>         absolute import, the module name is not ambiguous and excessive
>         stat()
>         calls can be avoided.
>
>         Python 2.5 introduced the "absolute_import" feature to __future__ to
>         enable Python 2.x to import like Python 3. Adopting
>         "absolute_import"
>         makes dual compatibility with Python 3 easier to achieve. In my
>         opinion, it also makes code easier to read since there is no
>         ambiguity
>         as to where a module is coming from. With a project of Mercurial's
>         size (~120 .py files), this can be a real concern, especially for
>         new contributors.
>
>
>     I think the overall goal is great, CCing Augie on that as he has the
>     Python 3 compat hat on.
>
>     But I think using absolute import have some effect of how python
>     handle cycle, Augie will have that in his head. More feedback below
>
>         PEP-0328 also introduced the multiple line import statement. Simply
>         add parenthesis and you get more readable import statements. This
>         PEP also introduced relative imports ("from . import foo").
>
>
>     I would personnaly be happier to use explicite relative imports
>     though I feel they are more compact and easier to read while staying
>     explicit
>
>
> I /thought/ "from X import Y" would undo our lazy importer. However,
> lazy importing appears to still work as long as the names we're
> importing are modules and not things inside modules. So I guess I'll
> rewrite this series to use the more terse syntax, which we both prefer.

Actually I was suggesting using this:

   import .localrepo

But it apparently never survived the PEP bike-shedding. (sad panda)

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list