FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-132987: Support __index__() in the stat module by serhiy-storchaka · Pull Request #133097 · python/cpython · GitHub

Repository navigation

gh-132987: Support __index__() in the stat module - #133097

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:stat-unsigned-int-index
Apr 29, 2025
Merged

serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:stat-unsigned-int-index

Conversation

serhiy-storchaka commented Apr 28, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.

Use it for the mode arguments in filemode(), S_IMODE(), S_ISDIR(), etc.

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Comment thread Modules/_stat.c
value = PyLong_AsUnsignedLong(op);
if ((value == (unsigned long)-1) && PyErr_Occurred())
if (PyLong_Check(op)) {
value = PyLong_AsUnsignedLong(op);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

serhiy-storchaka merged commit c33efa8 into python:main Apr 29, 2025
serhiy-storchaka deleted the stat-unsigned-int-index branch April 29, 2025 16:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL