Why does `import __hello__` not automatically print "Hello World" anymore

This may be a rather esoteric question.

Python has some easter eggs I like to show my friends, one being

import __hello__
>>> Hello World!

With this one, I also know it has a practical use as a basic sanity check for import shenanigans
Now, in my memory I recall that it used to automatically print Hello World, but now I have to manually call __hello__.main() to make the message appear. I have tested it using those methods:

  1. via the interactive python interpreter
$ python
Python 3.13.7 (main, Aug 15 2025, 12:34:02) [GCC 15.2.1 20250813] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import __hello__
>>> # No output
  1. via python -c
$ python -c "import __hello__"
$ # No output
  1. via a file
$ echo "import __hello__" >> hello.py
$ python hello.py
$ # No output

I also found a source which says that this behaviour only started in Python 3.11

Hello world for python >= 3.11

>>> import __hello__
>>> __hello__.main()
Hello World!

I wonder if this there is a reason for this new behavior, I looked at the changelog of python and, using ctrl + f "__hello__" found two issues linked but nothing else. I can imagine some CI workflows may have been broken which expected Hello World in stdout after testing import __hello__, so I’m interested if there has been discussions around it or if this is a very weird regression which nobody noticed

Information that may be interesting
python --version --version

Python 3.13.7 (main, Aug 15 2025, 12:34:02) [GCC 15.2.1 20250813]

fastfetch --pipe (Logo manually removed)

laura@programs
--------------
OS: Arch Linux x86_64
Host: HP Laptop 15-dw3xxx
Kernel: Linux 6.16.1-arch1-1
Uptime: 4 days, 5 hours, 32 mins
Packages: 1498 (pacman)
Shell: bash 5.3.3
Display (AUO3791): 1920x1080 @ 60 Hz in 16" [Built-in]
DE: KDE Plasma 6.4.4
WM: KWin (Wayland)
WM Theme: exposeair
Theme: Breeze (ExposeAir) [Qt], Breeze [GTK2/3]
Icons: ExposeAir [Qt], ExposeAir [GTK2/3/4]
Font: Noto Sans (10pt) [Qt], Noto Sans (10pt) [GTK2/3/4]
Cursor: breeze (24px)
Terminal: konsole 25.8.0
CPU: 11th Gen Intel(R) Core(TM) i5-1135G7 (8) @ 4.20 GHz
GPU: Intel Iris Xe Graphics @ 1.30 GHz [Integrated]
Memory: 7.34 GiB / 15.36 GiB (48%)
Swap: 2.54 GiB / 16.00 GiB (16%)
Disk (/): 194.54 GiB / 475.92 GiB (41%) - btrfs
Local IP (wlan0): 192.168.179.11/24
Battery (PABAS0241231): 100% [AC Connected]
Locale: en_GB.UTF-8

You can get it from the system command line:

py -m __hello__

__hello__.py won’t print it when imported because of the check at the end:

if __name__ == '__main__':
    main()

I interpreted the original post to wonder why the behavior changed, not what the change was.

3 Likes

@eric.snow did this in commit: bpo-45019: Clean up the frozen __hello__ module. (gh-28374) · python/cpython@3814e20 · GitHub

as part of a larger commit series spanning PR #28319 and PR #28374.

Doesn’t seem like the change in behavior of this easter egg was given much discussion.

Surely such a drastic change requires a PEP! :slight_smile:

2 Likes

Presumably freezing the hello module brought such significant speed benefits that a PEP was simply unnecessary.

1 Like

(not sure if you are joking or not, but: the __hello__ module was already frozen before - it specifically exists to test frozen modules behaviors. This was an intentional change in behavior, not a side effect or necessary consequence of other changes)

2 Likes