[PATCH 2 of 8] localrepo: use absolute import

Augie Fackler raf at durin42.com
Tue May 26 09:24:32 CDT 2015


On Mon, May 25, 2015 at 10:15:46PM -0700, Gregory Szorc wrote:
> On Mon, May 25, 2015 at 9:56 PM, Pierre-Yves David <
> 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>
> >> # Date 1432580350 25200
> >> #      Mon May 25 11:59:10 2015 -0700
> >> # Node ID c2b845cda536ef0abc665befb19319f53bb6216e
> >> # Parent  f085ecda3b0e11341ecc119683d5fc47038540d4
> >> localrepo: use absolute import


> >> 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.

So, it works fine with our lazy importer, but you've just broken
everyone that imports Mercurial without using demandimport (which
probably includes kallithea, definitely includes hgsubversion's
testsuite, etc.) We'll need to resolve the cycles before we can finish
this switch :(

(Alternatively: prove me wrong that it doesn't break things, but my
recollection is that this will be catastrophic for those not using
demandimport.)

> >
> >  This patch switches localrepo.py to use absolute imports as well as
> >> modern import syntax. While I was here, I also reordered imports:
> >> standard library first, Mercurial second, each alphabetized within its
> >> subset.
> >>
> >
> > +1 for standard library first
> >
> > +1 for one import per line
> >
> > +1 alphabetized import

+1 to all of the above.

> >
> > --
> > Pierre-Yves David
> >


More information about the Mercurial-devel mailing list