[issue39637] Probably incorrect message after failed import

2020-02-15 Thread Rick van Rein


Change by Rick van Rein :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39637] Probably incorrect message after failed import

2020-02-15 Thread Rick van Rein


Rick van Rein  added the comment:

Thanks for explaining.  It is indeed confusing, even though I'm quite 
experienced with Python.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39637] Probably incorrect message after failed import

2020-02-15 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

> Shouldn't that say that "'environ' is not a package" instead?

No. The os module is special, so I'll talk about the usual case first.

Normally, for `import spam.eggs` to succeed, *spam* has to be a package, and 
*eggs* has to be either a sub-module inside that package, or a sub-package. So 
the general error message is correct. You can't normally use the dotted import 
syntax to import functions from a module.

But the `os` module is special: it is very old, pre-dating the invention of 
packages, and the `os` module fakes a pretend package for `os.path` by doing 
this:

sys.modules['os.path'] = path


So even though `os` is not a package, you can still use dotted package syntax 
to import `os.path`.

I guess this was intended as a convenience, without considering how this could 
be confusing.

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39637] Probably incorrect message after failed import

2020-02-15 Thread Rick van Rein


New submission from Rick van Rein :

The following error message surprises me:

>>> import os.environ
Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'os.environ'; 'os' is not a package

Shouldn't that say that "'environ' is not a package" instead?

After all, 'os' will support

>>> import os.path
>>> 

This is confusing :)

--
components: Interpreter Core
messages: 362011
nosy: vanrein
priority: normal
severity: normal
status: open
title: Probably incorrect message after failed import
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com