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-132987: Support __index__() in the stat module#133097

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
Changes fromall commits
Commits
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
16 changes: 14 additions & 2 deletionsModules/_stat.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -295,9 +295,21 @@ _PyLong_AsMode_t(PyObject *op)
unsigned long value;
mode_t mode;

value = PyLong_AsUnsignedLong(op);
if ((value == (unsigned long)-1) && PyErr_Occurred())
if (PyLong_Check(op)) {
value = PyLong_AsUnsignedLong(op);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This code path looks like a micro-optimization (to avoid PyNumber_Index). I don't think that it's worth it.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not only. Many functions likePyLong_AsUnsignedLong() andPyLong_AsUnsignedLongMask(), many setters and converter, only call__index__() if the argument notint. So there would be a subtle behavior difference when the argument is an instance of theint subclass which defines__index__(). And calling__index__() forint subclass adds overhead.

But this is not completely consistent, so this may not make large difference.

}
else {
op = PyNumber_Index(op);
if (op == NULL) {
return (mode_t)-1;
}
value = PyLong_AsUnsignedLong(op);
Py_DECREF(op);
}

if ((value == (unsigned long)-1) && PyErr_Occurred()) {
return (mode_t)-1;
}

mode = (mode_t)value;
if ((unsigned long)mode != value) {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp