mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
gh-119180: No longer set __annotations__
in __main__
(#124634)
This commit is contained in:
parent
b79a21ea42
commit
365dffbaad
4 changed files with 4 additions and 9 deletions
|
@ -849,7 +849,6 @@ class RunStringTests(TestBase):
|
||||||
ns.pop('__loader__')
|
ns.pop('__loader__')
|
||||||
self.assertEqual(ns, {
|
self.assertEqual(ns, {
|
||||||
'__name__': '__main__',
|
'__name__': '__main__',
|
||||||
'__annotations__': {},
|
|
||||||
'__doc__': None,
|
'__doc__': None,
|
||||||
'__package__': None,
|
'__package__': None,
|
||||||
'__spec__': None,
|
'__spec__': None,
|
||||||
|
|
|
@ -1080,7 +1080,7 @@ class TestMain(ReplTestCase):
|
||||||
|
|
||||||
@force_not_colorized
|
@force_not_colorized
|
||||||
def test_exposed_globals_in_repl(self):
|
def test_exposed_globals_in_repl(self):
|
||||||
pre = "['__annotations__', '__builtins__'"
|
pre = "['__builtins__'"
|
||||||
post = "'__loader__', '__name__', '__package__', '__spec__']"
|
post = "'__loader__', '__name__', '__package__', '__spec__']"
|
||||||
output, exit_code = self.run_repl(["sorted(dir())", "exit()"])
|
output, exit_code = self.run_repl(["sorted(dir())", "exit()"])
|
||||||
if "can't use pyrepl" in output:
|
if "can't use pyrepl" in output:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
The ``__main__`` module no longer always contains an ``__annotations__``
|
||||||
|
dictionary in its global namespace.
|
|
@ -2503,18 +2503,12 @@ finalize_subinterpreters(void)
|
||||||
static PyStatus
|
static PyStatus
|
||||||
add_main_module(PyInterpreterState *interp)
|
add_main_module(PyInterpreterState *interp)
|
||||||
{
|
{
|
||||||
PyObject *m, *d, *ann_dict;
|
PyObject *m, *d;
|
||||||
m = PyImport_AddModuleObject(&_Py_ID(__main__));
|
m = PyImport_AddModuleObject(&_Py_ID(__main__));
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return _PyStatus_ERR("can't create __main__ module");
|
return _PyStatus_ERR("can't create __main__ module");
|
||||||
|
|
||||||
d = PyModule_GetDict(m);
|
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__");
|
int has_builtins = PyDict_ContainsString(d, "__builtins__");
|
||||||
if (has_builtins < 0) {
|
if (has_builtins < 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue