Author gvanrossum
Recipients Arfrever, asvetlov, barry, brett.cannon, chris.jerdonek, cvrebert, eric.snow, ezio.melotti, gvanrossum, pitrou, python-dev, serhiy.storchaka
Date 2013-07-01.00:00:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1372636810.42.0.61547713627.issue15767@psf.upfronthosting.co.za>
In-reply-to
Content
Hey Brett,

Sorry for reopening this issue.  I am confused by the spec for ModuleNotFoundError.  Look at this (in a pretty recent repo):

$ ./python.exe
Python 3.4.0a0 (default:8f22e03f5f07, Jun 27 2013, 08:49:16) 
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin
Type "help", "copyright", "credits" or "license" for more information.

[1]
>>> import bogus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bogus'

[2]
>>> from re import bogus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: cannot import name bogus

[3]
>>> import re.bogus
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1553, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 're.bogus'; re is not a package

Given that it knows that re is not a package, I would have expected [2] not to raise ModuleNotFoundError, because there is no way that bogus could be a package.  OTOH, I would have expected [3] to raise ModuleNotFoundError, since this syntax implies that bogus is a submodule.

But perhaps I am missing something and I need to look at the distinction differently?  Sadly the docs don't really help me; they claim to explain why I get ModuleNotFoundError in [2], but the motivation "as the specific attribute being requested cannot be known a priori to be a module or some other type of object" seems wrong, given that [3] proves it *does* know.

(Aside, it's also odd that bogus is quoted in the error message for [1] and [3] but not for [2] -- in fact the phrasing of [2] compared to [1] seems arbitrarily different, both seem to tell me exactly the same thing.)
History
Date User Action Args
2013-07-01 00:00:10gvanrossumsetrecipients: + gvanrossum, barry, brett.cannon, pitrou, ezio.melotti, Arfrever, cvrebert, asvetlov, chris.jerdonek, python-dev, eric.snow, serhiy.storchaka
2013-07-01 00:00:10gvanrossumsetmessageid: <1372636810.42.0.61547713627.issue15767@psf.upfronthosting.co.za>
2013-07-01 00:00:10gvanrossumlinkissue15767 messages
2013-07-01 00:00:10gvanrossumcreate