Skip to content

Commit c33efa8

Browse files
pythongh-132987: Support __index__() in the stat module (pythonGH-133097)
Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.
1 parent acb222c commit c33efa8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Modules/_stat.c

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy