Skip to content

gh-108638: Fix stat.filemode() when _stat is missing #108639

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Aug 29, 2023

Change the pure Python implementation of stat.filemode() for unknown file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.

Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
@vstinner
Copy link
Member Author

I don't think that this change should be backported to Python 3.11 and 3.12: the _stat is always built on these versions. Adopting the test suite for PyPy is nice, but I don't think that it's worth it to backport the change.

@vstinner vstinner enabled auto-merge (squash) August 29, 2023 15:44
@vstinner vstinner merged commit b62a760 into python:main Aug 29, 2023
for bit, char in table:
if mode & bit == bit:
perm.append(char)
break
else:
perm.append("-")
if index == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if index == 0:
if not perm:

And you can remove index.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right, feel free to write a follow-up PR if you want, sadly you reviewed the change just after it got merged automatically. I have not preference between enumerate() + if index == 0 and not perm.

Copy link
Member Author

Choose a reason for hiding this comment

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

_stat.filemode() and stat.filemode() implementations are very different. I tried to write a minimum fix.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, so there is a _stat.filemode()? I noticed that the Python implementation always use constants defined in Python, even if they are overwritten by _stat later. I was not sure whether this is good or bad. On one hand, the original use case was for tar files, which can came from other systems. On other hand, it should work with local files.

@vstinner vstinner deleted the filemode branch August 29, 2023 15:51
@gvanrossum
Copy link
Member

This PR feels like a good example of why you should wait a bit longer for reviews before merging PRs. Also please allow time for folks in different timezones to review before merging. Waiting a few days with a minor fix like this isn't the end of the world right?

@vstinner
Copy link
Member Author

Do you mean that you want to change the implémentation?

@gvanrossum
Copy link
Member

No, I mean that there was a comment with a suggestion that you could have taken into account before merging, rather than saying "oops I merged already go make your own PR if you want to". This sounds like you were too hasty merging.

@serhiy-storchaka
Copy link
Member

It is just a coincidence. I started to write a review when the PR was not yet merged, but when I published my comment it was already merged. This has happened several times already, and not only with Victor's PRs. The longer the PR waits, the less likely it is to happen.

It's not a big problem if it doesn't happen all the time. In this case, it was just a little style suggestion, and it's up to Victor to accept it or not.

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.

4 participants