diff tests/test-demandimport.py.out @ 30647:1914db1b7d9e stable

demandimport: do not raise ImportError for unknown item in fromlist This is the behavior of the default __import__() function, which doesn't validate the existence of the fromlist items. Later on, the missing attribute is detected while processing the import statement. https://hg.python.org/cpython/file/v2.7.13/Python/import.c#l2575 The comtypes library relies on this (maybe) undocumented behavior, and we got a bug report to TortoiseHg, sigh. https://bitbucket.org/tortoisehg/thg/issues/4647/ The test added at 26a4e46af2bc verifies the behavior of the import statement, so this patch only adds the test of __import__() function and works around CPython/PyPy difference.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 19 Dec 2016 22:46:00 +0900
parents 26a4e46af2bc
children 252d2260c74e
line wrap: on
line diff
--- a/tests/test-demandimport.py.out	Thu Dec 08 23:59:36 2016 +0800
+++ b/tests/test-demandimport.py.out	Mon Dec 19 22:46:00 2016 +0900
@@ -18,4 +18,6 @@
 re = <proxied module 'sys'>
 contextlib = <unloaded module 'contextlib'>
 contextlib.unknownattr = ImportError: cannot import name unknownattr
+__import__('contextlib', ..., ['unknownattr']) = <module 'contextlib' from '?'>
+hasattr(contextlibimp, 'unknownattr') = False
 node = <module 'mercurial.node' from '?'>