classification
Title: import __hello__ is broken in Python 3
Type: Stage:
Components: Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Solomon Ucko, Trundle, benjamin.peterson, eric.araujo, ezio.melotti, georg.brandl, pablogsal, python-dev, vstinner
Priority: deferred blocker Keywords: patch

Created on 2011-03-20 15:15 by vstinner, last changed 2019-03-07 12:05 by Solomon Ucko. This issue is now closed.

Files
File name Uploaded Description Edit
issue11614.patch Trundle, 2011-05-12 21:24 review
issue11614_!.patch Trundle, 2011-05-12 22:19 review
Messages (19)
msg131499 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-03-20 15:15
import __hello__ doesn't print any message!!!
msg131500 - (view) Author: Andreas Stührk (Trundle) * Date: 2011-03-20 15:33
That was changed in [a2213060d9dd], see issue #1414.
msg132123 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-25 17:47
What’s import __hello__?  I don’t have it in any version from 2.4 to 3.2.
msg132127 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-25 17:52
Okay, it doesn’t work with -m __hello__, but using -c "import __hello__" I can see the message in all versions.
msg132221 - (view) Author: Andreas Stührk (Trundle) * Date: 2011-03-26 10:01
On Fri, Mar 25, 2011 at 5:52 PM, Éric Araujo <report@bugs.python.org> wrote:
> Okay, it doesn’t work with -m __hello__, but using -c "import __hello__" I can see the message in all versions.

Can you elaborate on that? I.e. the versions and the actual message.
The current bytecode of the __hello__ module is (default branch):

  1           0 LOAD_CONST               1 (True)
              3 STORE_NAME               1 (initialized)
              6 LOAD_CONST               0 (None)
              9 RETURN_VALUE

I'd be a bit surprised if that really prints a message.
msg132370 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-03-27 22:07
I can see the message (“Hello world...”) in 2.4 to 2.7, but actually not in 3.x.
msg135860 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-05-12 20:36
Why is this still open, and more importantly, why is it a release blocker?
msg135864 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-12 20:44
> Why is this still open

Because import __hello__ doesn't print hello.

> and more importantly, why is it a release blocker?

Because it is a very important issue!
msg135868 - (view) Author: Andreas Stührk (Trundle) * Date: 2011-05-12 21:24
A patch against 3.1. The new bytecode is now:

  1           0 LOAD_CONST               2 (True) 
              3 STORE_NAME               1 (initialized) 

  2           6 LOAD_NAME                2 (print) 
              9 LOAD_CONST               0 ('Hello world...') 
             12 CALL_FUNCTION            1 
             15 POP_TOP              
             16 LOAD_CONST               1 (None) 
             19 RETURN_VALUE
msg135869 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-12 21:40
+print("Hello world...")

I would prefer a more positive "Hello World!", but thanks for the patch.
msg136095 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-16 14:35
New changeset 44fd95cead7b by Victor Stinner in branch '3.1':
Issue #11614: import __hello__ prints "Hello World!". Patch written by Andreas
http://hg.python.org/cpython/rev/44fd95cead7b

New changeset 2c5736e8a221 by Victor Stinner in branch '3.2':
(Merge 3.1) Issue #11614: import __hello__ prints "Hello World!". Patch written
http://hg.python.org/cpython/rev/2c5736e8a221

New changeset 79c49d2fc768 by Victor Stinner in branch 'default':
(Merge 3.2) Issue #11614: import __hello__ prints "Hello World!". Patch written
http://hg.python.org/cpython/rev/79c49d2fc768
msg136096 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-16 14:37
Thanks Andreas for your fix! Python 3 is now better than Python 2: it prints "Hello World!" instead of "Hello World...".
msg136101 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-16 15:01
New changeset 9e1d7cd15d2e by Victor Stinner in branch '3.1':
Issue #11614: Fix importlib tests for the new __hello__ module
http://hg.python.org/cpython/rev/9e1d7cd15d2e

New changeset 6119f6cc9b2d by Victor Stinner in branch '3.2':
(Merge 3.1) Issue #11614: Fix importlib tests for the new __hello__ module
http://hg.python.org/cpython/rev/6119f6cc9b2d

New changeset b61a1cd4943b by Victor Stinner in branch 'default':
(Merge 3.2) Issue #11614: Fix importlib tests for the new __hello__ module
http://hg.python.org/cpython/rev/b61a1cd4943b
msg136105 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-16 15:20
New changeset 9a4d4506680a by Victor Stinner in branch '3.1':
Issue #11614: Fix test_linecache, cjkencodings_test.py doesn't exist anymore
http://hg.python.org/cpython/rev/9a4d4506680a

New changeset 43cbfacae463 by Victor Stinner in branch '3.2':
(Merge 3.1) Issue #11614: Fix test_linecache, cjkencodings_test.py doesn't
http://hg.python.org/cpython/rev/43cbfacae463

New changeset 06473da99270 by Victor Stinner in branch 'default':
(Merge 3.2) Issue #11614: Fix test_linecache, cjkencodings_test.py doesn't
http://hg.python.org/cpython/rev/06473da99270
msg136107 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-16 15:23
> New changeset 9a4d4506680a by Victor Stinner in branch '3.1':
> Issue #11614: Fix test_linecache, cjkencodings_test.py doesn't exist anymore

Oh, these commits are related to #12057, not this one.
msg136131 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-16 23:19
New changeset 47bc3509f76b by Victor Stinner in branch '2.7':
Issue #11614: Fix test_linecache, cjkencodings_test.py doesn't exist anymore
http://hg.python.org/cpython/rev/47bc3509f76b
msg337352 - (view) Author: Solomon Ucko (Solomon Ucko) Date: 2019-03-07 02:43
The byte code could be further optimized (because this is such a speed-critical module! :)):

  1           0 LOAD_CONST               2 (True) 
              3 STORE_NAME               1 (initialized) 

  2           6 LOAD_NAME                2 (print) 
              9 LOAD_CONST               0 ('Hello world...') 
             12 CALL_FUNCTION            1 
             15 RETURN_VALUE
msg337385 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-07 11:38
> The byte code could be further optimized (because this is such a speed-critical module! :)): (...)

You propose to replace

              8 CALL_FUNCTION            1
             10 POP_TOP
             12 LOAD_CONST               2 (None)
             14 RETURN_VALUE

with:

             12 CALL_FUNCTION            1 
             15 RETURN_VALUE

It changes the semantics of Python. Technically, you *can* override the print() builtin function:

vstinner@apu$ ./python
Python 3.8.0a2+ (heads/master:dc078947a5, Mar  7 2019, 12:23:23) 
>>> import builtins
>>> def mock(*args, **kw): return 3
... 
>>> builtins.print=mock
>>> print("hello")
3
>>> import __phello__
>>> # doesn't print anything
... 

It would be possible if you ensure that print() isn't replaced.

Longer explanation:
https://fatoptimizer.readthedocs.io/en/latest/semantics.html

To use more efficient bytecode without modying the Python semantics, you need to deoptimize if print() is replaced. I implemented that in my old FAT Python project :-)
https://fatoptimizer.readthedocs.io/en/latest/optimizations.html#call-pure

--

I would be more interested by a tool to update/regenerate M___hello__ in Python/frozen.c.
msg337390 - (view) Author: Solomon Ucko (Solomon Ucko) Date: 2019-03-07 12:05
> It changes the semantics of Python.

When would the return value actually matter? Would it affect the value of the variable `__hello__`?
History
Date User Action Args
2019-03-07 12:05:32Solomon Uckosetmessages: + msg337390
2019-03-07 11:42:36pablogsalsetnosy: + pablogsal
2019-03-07 11:38:41vstinnersetmessages: + msg337385
2019-03-07 02:43:29Solomon Uckosetnosy: + Solomon Ucko
messages: + msg337352
2011-05-16 23:19:23python-devsetmessages: + msg136131
2011-05-16 15:23:33vstinnersetmessages: + msg136107
2011-05-16 15:20:54python-devsetmessages: + msg136105
2011-05-16 15:01:28python-devsetmessages: + msg136101
2011-05-16 14:37:02vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg136096
2011-05-16 14:35:46python-devsetnosy: + python-dev
messages: + msg136095
2011-05-15 15:47:54georg.brandlsetpriority: release blocker -> deferred blocker
2011-05-12 22:19:03Trundlesetfiles: + issue11614_!.patch
2011-05-12 21:40:18vstinnersetmessages: + msg135869
2011-05-12 21:24:52Trundlesetfiles: + issue11614.patch
keywords: + patch
messages: + msg135868
2011-05-12 20:44:53vstinnersetmessages: + msg135864
2011-05-12 20:36:28georg.brandlsetmessages: + msg135860
2011-03-27 22:07:08eric.araujosetmessages: + msg132370
2011-03-26 10:01:16Trundlesetmessages: + msg132221
2011-03-25 18:15:07ezio.melottisetnosy: + ezio.melotti
2011-03-25 17:52:48eric.araujosetmessages: + msg132127
2011-03-25 17:47:42eric.araujosetnosy: + eric.araujo
messages: + msg132123
2011-03-20 15:33:04Trundlesetnosy: + Trundle
messages: + msg131500
2011-03-20 15:15:10vstinnercreate