[issue26160] Tutorial incorrectly claims that (explicit) relative imports don't work in the main module

2016-01-28 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +ezio.melotti

___
Python tracker 

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



[issue26160] Tutorial incorrectly claims that (explicit) relative imports don't work in the main module

2016-01-23 Thread Kevin Norris

Kevin Norris added the comment:

>It could be misleading saying “the name of the current package”, because the 
>import could be relative to the a higher level parent package if more than one 
>dot is specified.

While this is correct, Python still uses __package__ to determine what to 
import in that case.  I simply replaced "__package__" with "the name of the 
current package" to make it easier to read, much as the original text replaces 
"__name__" with "the name of the current module."

>Then point out that relative imports won’t work with ``python file.py`` or 
>interactive mode, but don’t mention “-m” (or the other ways to run scripts and 
>modules).

SGTM if you can find a reasonable way of phrasing that.

--

___
Python tracker 

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



[issue26160] Tutorial incorrectly claims that (explicit) relative imports don't work in the main module

2016-01-20 Thread Martin Panter

Martin Panter added the comment:

Yes 2.7 is open for changes to the documentation like this, as is 3.5+.

It’s been a while since I looked at the tutorial. Does it even mention the 
“python -m” mode? I don’t think this is the right place to introduce it.

Perhaps it would be okay to just say relative imports are based on the _full_ 
name of the current module. It could be misleading saying “the name of the 
current package”, because the import could be relative to the a higher level 
parent package if more than one dot is specified. Then point out that relative 
imports won’t work with ``python file.py`` or interactive mode, but don’t 
mention “-m” (or the other ways to run scripts and modules).

--
nosy: +martin.panter
versions:  -Python 3.2, Python 3.3, Python 3.4

___
Python tracker 

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



[issue26160] Tutorial incorrectly claims that (explicit) relative imports don't work in the main module

2016-01-19 Thread Kevin Norris

New submission from Kevin Norris:

The tutorial contains this statement:

Note that relative imports are based on the name of the current module. Since 
the name of the main module is always "__main__", modules intended for use as 
the main module of a Python application must always use absolute imports.

See . 
 The wording is slightly different in the 2.7 version of the tutorial to 
account for the existence of implicit relative imports, but it clearly states 
that explicit relative imports suffer from this limitation.

As of PEP 366, this is no longer true.  You can do (explicit) relative imports 
in the main module just fine (though with some minor caveats w.r.t. using the 
-m flag vs. specifying the .py file directly).  PEP 366 has a Python-Version of 
2.6, 3.0, so every sufficiently recent version of the tutorial is wrong.

It's probably not a good idea to get too far into those caveats in the 
tutorial.  I'd suggest wording like this:

Note that relative imports are based on the name of the current package.  If 
Python is invoked with the -m switch, it can determine the package name 
automatically, but if it is invoked directly as ``python file.py``, relative 
imports will not work because Python doesn't know what package file.py belongs 
to.

It might be worth mentioning __package__ here, too, but we don't want to get 
too far down the rabbit hole of trivia (e.g. PEP 366 discusses sys.path 
manipulation, and for that you probably want to use __file__ instead of 
hard-coding the path, and then you have to talk about zipimports, and then, and 
then, and then...!).

(For the record, is the 2.7 tutorial still under active support?  Is it okay to 
report bugs in it?)

--
assignee: docs@python
components: Documentation
messages: 258650
nosy: Kevin.Norris, docs@python
priority: normal
severity: normal
status: open
title: Tutorial incorrectly claims that (explicit) relative imports don't work 
in the main module
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

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