summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test__interpreters.py1
-rw-r--r--Lib/test/test_pyrepl/test_pyrepl.py2
-rw-r--r--Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-13-25-01.gh-issue-119180.k_JCX0.rst2
-rw-r--r--Python/pylifecycle.c8
4 files changed, 4 insertions, 9 deletions
diff --git a/Lib/test/test__interpreters.py b/Lib/test/test__interpreters.py
index f493a92..14cd50b 100644
--- a/Lib/test/test__interpreters.py
+++ b/Lib/test/test__interpreters.py
@@ -849,7 +849,6 @@ class RunStringTests(TestBase):
ns.pop('__loader__')
self.assertEqual(ns, {
'__name__': '__main__',
- '__annotations__': {},
'__doc__': None,
'__package__': None,
'__spec__': None,
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 0f3e999..36f940e 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1080,7 +1080,7 @@ class TestMain(ReplTestCase):
@force_not_colorized
def test_exposed_globals_in_repl(self):
- pre = "['__annotations__', '__builtins__'"
+ pre = "['__builtins__'"
post = "'__loader__', '__name__', '__package__', '__spec__']"
output, exit_code = self.run_repl(["sorted(dir())", "exit()"])
if "can't use pyrepl" in output:
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-13-25-01.gh-issue-119180.k_JCX0.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-13-25-01.gh-issue-119180.k_JCX0.rst
new file mode 100644
index 0000000..4cdbb20
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-13-25-01.gh-issue-119180.k_JCX0.rst
@@ -0,0 +1,2 @@
+The ``__main__`` module no longer always contains an ``__annotations__``
+dictionary in its global namespace.
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 27faf72..8aebbe5 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2503,18 +2503,12 @@ finalize_subinterpreters(void)
static PyStatus
add_main_module(PyInterpreterState *interp)
{
- PyObject *m, *d, *ann_dict;
+ PyObject *m, *d;
m = PyImport_AddModuleObject(&_Py_ID(__main__));
if (m == NULL)
return _PyStatus_ERR("can't create __main__ module");
d = PyModule_GetDict(m);
- ann_dict = PyDict_New();
- if ((ann_dict == NULL) ||
- (PyDict_SetItemString(d, "__annotations__", ann_dict) < 0)) {
- return _PyStatus_ERR("Failed to initialize __main__.__annotations__");
- }
- Py_DECREF(ann_dict);
int has_builtins = PyDict_ContainsString(d, "__builtins__");
if (has_builtins < 0) {