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

Appearance settings

Commit c33efa8

Browse filesBrowse files
gh-132987: Support __index__() in the stat module (GH-133097)
Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.
1 parent acb222c commit c33efa8
Copy full SHA for c33efa8

File tree

Expand file treeCollapse file tree

1 file changed

+14
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-2
lines changed

‎Modules/_stat.c

Copy file name to clipboardExpand all lines: Modules/_stat.c
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,21 @@ _PyLong_AsMode_t(PyObject *op)
295295
unsigned long value;
296296
mode_t mode;
297297

298-
value = PyLong_AsUnsignedLong(op);
299-
if ((value == (unsigned long)-1) && PyErr_Occurred())
298+
if (PyLong_Check(op)) {
299+
value = PyLong_AsUnsignedLong(op);
300+
}
301+
else {
302+
op = PyNumber_Index(op);
303+
if (op == NULL) {
304+
return (mode_t)-1;
305+
}
306+
value = PyLong_AsUnsignedLong(op);
307+
Py_DECREF(op);
308+
}
309+
310+
if ((value == (unsigned long)-1) && PyErr_Occurred()) {
300311
return (mode_t)-1;
312+
}
301313

302314
mode = (mode_t)value;
303315
if ((unsigned long)mode != value) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.