Issue #15715: Ignore failed imports triggered by the use of fromlist.

When the fromlist argument is specified for __import__() and the
attribute doesn't already exist, an import is attempted. If that fails
(e.g. module doesn't exist), the ImportError will now be silenced (for
backwards-compatibility). This *does not* affect
``from ... import ...`` statements.

Thanks to Eric Snow for the patch and Simon Feltman for reporting the
regression.
This commit is contained in:
Brett Cannon 2012-08-17 13:21:16 -04:00
parent b391b24efe
commit 7385adc84c
4 changed files with 474 additions and 458 deletions

View file

@ -334,6 +334,12 @@ class ImportTests(unittest.TestCase):
del sys.path[0]
remove_files(TESTFN)
def test_bogus_fromlist(self):
try:
__import__('http', fromlist=['blah'])
except ImportError:
self.fail("fromlist must allow bogus names")
class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points