Skip to content

Commit 365dffb

Browse files
gh-119180: No longer set __annotations__ in __main__ (#124634)
1 parent b79a21e commit 365dffb

File tree

4 files changed

+4
-9
lines changed

4 files changed

+4
-9
lines changed

Lib/test/test__interpreters.py

-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,6 @@ def test_execution_namespace_is_main(self):
849849
ns.pop('__loader__')
850850
self.assertEqual(ns, {
851851
'__name__': '__main__',
852-
'__annotations__': {},
853852
'__doc__': None,
854853
'__package__': None,
855854
'__spec__': None,

Lib/test/test_pyrepl/test_pyrepl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ def setUp(self):
10801080

10811081
@force_not_colorized
10821082
def test_exposed_globals_in_repl(self):
1083-
pre = "['__annotations__', '__builtins__'"
1083+
pre = "['__builtins__'"
10841084
post = "'__loader__', '__name__', '__package__', '__spec__']"
10851085
output, exit_code = self.run_repl(["sorted(dir())", "exit()"])
10861086
if "can't use pyrepl" in output:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``__main__`` module no longer always contains an ``__annotations__``
2+
dictionary in its global namespace.

Python/pylifecycle.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -2503,18 +2503,12 @@ finalize_subinterpreters(void)
25032503
static PyStatus
25042504
add_main_module(PyInterpreterState *interp)
25052505
{
2506-
PyObject *m, *d, *ann_dict;
2506+
PyObject *m, *d;
25072507
m = PyImport_AddModuleObject(&_Py_ID(__main__));
25082508
if (m == NULL)
25092509
return _PyStatus_ERR("can't create __main__ module");
25102510

25112511
d = PyModule_GetDict(m);
2512-
ann_dict = PyDict_New();
2513-
if ((ann_dict == NULL) ||
2514-
(PyDict_SetItemString(d, "__annotations__", ann_dict) < 0)) {
2515-
return _PyStatus_ERR("Failed to initialize __main__.__annotations__");
2516-
}
2517-
Py_DECREF(ann_dict);
25182512

25192513
int has_builtins = PyDict_ContainsString(d, "__builtins__");
25202514
if (has_builtins < 0) {

0 commit comments

Comments
 (0)