[PATCH 1 of 3 v3] demandimport: suppport rejecting modules based on requested properties

Yuya Nishihara yuya at tcha.org
Mon Sep 26 09:55:21 EDT 2016


On Wed, 21 Sep 2016 19:09:32 +0000, timeless wrote:
> # HG changeset patch
> # User timeless <timeless at mozdev.org>
> # Date 1474484347 0
> #      Wed Sep 21 18:59:07 2016 +0000
> # Node ID 33884775ee4b22109085387b0317aa17db73c483
> # Parent  982fe7cdb28bb263a96b1bc2c9c3b8aedb025ab6
> # Available At https://bitbucket.org/timeless/mercurial-crew
> #              hg pull https://bitbucket.org/timeless/mercurial-crew -r 33884775ee4b
> demandimport: suppport rejecting modules based on requested properties
>
> Some code uses:
> try:
>  from Foo import Bar
> except ImportError:
>  from Foo import Bar2
> 
> demandimport exposes Bar as an unloaded module without checking to
> see whether or not it really exists this enables it to improve loading
> speed.
> 
> Unfortunately, any code that expects to get an ImportError won't get
> one.

Sorry for late reply, but I still don't get why we need "rejects" dict other
than the current "ignore" list. Can't we just add 'Foo.Bar' to ignore?

> without demandimport:
> >>> from contextlib import _GeneratorContextManager
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: cannot import name _GeneratorContextManager

In this case, we'll probably be able to reject all unknown attributes since
'contextlib' is known to not be a package. Making a demandmod for that would
be useless.


More information about the Mercurial-devel mailing list