https://github.com/python/cpython/commit/365dffbaada421db8fdb684a84d1fb311b75ec40
commit: 365dffbaada421db8fdb684a84d1fb311b75ec40
branch: main
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2024-09-27T05:49:43-07:00
summary:
gh-119180: No longer set `__annotations__` in `__main__` (#124634)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-13-25-01.gh-issue-119180.k_JCX0.rst
M Lib/test/test__interpreters.py
M Lib/test/test_pyrepl/test_pyrepl.py
M Python/pylifecycle.c
diff --git a/Lib/test/test__interpreters.py b/Lib/test/test__interpreters.py
index f493a92e0ddce8..14cd50bd30502c 100644
--- a/Lib/test/test__interpreters.py
+++ b/Lib/test/test__interpreters.py
@@ -849,7 +849,6 @@ def test_execution_namespace_is_main(self):
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 0f3e9996e77e45..36f940eaea4eac 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1080,7 +1080,7 @@ def setUp(self):
@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 00000000000000..4cdbb205c962c4
--- /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 27faf723745c21..8aebbe5c405ffe 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) {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]