gh-132987: Support __index__() in the stat module#133097
gh-132987: Support __index__() in the stat module#133097serhiy-storchaka merged 1 commit intopython:mainfrom
Conversation
Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.
| value = PyLong_AsUnsignedLong(op); | ||
| if ((value == (unsigned long)-1) && PyErr_Occurred()) | ||
| if (PyLong_Check(op)) { | ||
| value = PyLong_AsUnsignedLong(op); |
There was a problem hiding this comment.
This code path looks like a micro-optimization (to avoid PyNumber_Index). I don't think that it's worth it.
There was a problem hiding this comment.
Not only. Many functions like PyLong_AsUnsignedLong() and PyLong_AsUnsignedLongMask(), many setters and converter, only call __index__() if the argument not int. So there would be a subtle behavior difference when the argument is an instance of the int subclass which defines __index__(). And calling __index__() for int subclass adds overhead.
But this is not completely consistent, so this may not make large difference.
Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.