Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-105340: include hidden fast-locals in locals()#105715

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
carljm merged 11 commits intopython:mainfromcarljm:modulelocals
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
also fix dir()
  • Loading branch information
@carljm
carljm committedJun 16, 2023
commit1e277218a315268b1ae06320e3eb448291cc9ab3
13 changes: 11 additions & 2 deletionsLib/test/test_listcomps.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -545,12 +545,21 @@ def test_iter_var_available_in_locals(self):
y = 0
items = [locals()["x"] for x in l]
items2 = [vars()["x"] for x in l]
items3 = [eval("x") for x in l]
items3 = [("x" in dir()) for x in l]
items4 = [eval("x") for x in l]
# x is available, and does not overwrite y
[exec("y = x") for x in l]
"""
self._check_in_scopes(
code, {"items": [1, 2], "items2": [1, 2], "items3": [1, 2], "y": 0})
code,
{
"items": [1, 2],
"items2": [1, 2],
"items3": [True, True],
"items4": [1, 2],
"y": 0
}
)


__test__ = {'doctests' : doctests}
Expand Down
7 changes: 4 additions & 3 deletionsObjects/object.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1690,13 +1690,15 @@ _dir_locals(void)
PyObject *names;
PyObject *locals;

locals =PyEval_GetLocals();
locals =PyEval_GetFrameLocals();
if (locals == NULL)
return NULL;

names = PyMapping_Keys(locals);
if (!names)
Py_DECREF(locals);
if (!names) {
return NULL;
}
if (!PyList_Check(names)) {
PyErr_Format(PyExc_TypeError,
"dir(): expected keys() of locals to be a list, "
Expand All@@ -1708,7 +1710,6 @@ _dir_locals(void)
Py_DECREF(names);
return NULL;
}
/* the locals don't need to be DECREF'd */
return names;
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp