Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-119180: No longer set __annotations__ in __main__ #124634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``__main__`` module no longer always contains an ``__annotations__``
dictionary in its global namespace.
8 changes: 1 addition & 7 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading