]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-119180: No longer set `__annotations__` in `__main__` (#124634)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Fri, 27 Sep 2024 12:49:43 +0000 (05:49 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Sep 2024 12:49:43 +0000 (05:49 -0700)
Lib/test/test__interpreters.py
Lib/test/test_pyrepl/test_pyrepl.py
Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-13-25-01.gh-issue-119180.k_JCX0.rst [new file with mode: 0644]
Python/pylifecycle.c

index f493a92e0ddce81dc5c5f2b9572d56da689a4fec..14cd50bd30502cec5dfa1f72330ed5e929d1f6a9 100644 (file)
@@ -849,7 +849,6 @@ class RunStringTests(TestBase):
         ns.pop('__loader__')
         self.assertEqual(ns, {
             '__name__': '__main__',
-            '__annotations__': {},
             '__doc__': None,
             '__package__': None,
             '__spec__': None,
index 0f3e9996e77e45649eaed751a3233ba3dfef940e..36f940eaea4eac10f05fa80cfd5167819061d924 100644 (file)
@@ -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 (file)
index 0000000..4cdbb20
--- /dev/null
@@ -0,0 +1,2 @@
+The ``__main__`` module no longer always contains an ``__annotations__``
+dictionary in its global namespace.
index 27faf723745c21193cc93789042e61805101e480..8aebbe5c405ffe0d2dbd2cdd980794a8fc3521ca 100644 (file)
@@ -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) {