Visitar URL original
Clarify glob logic a bit by encukou · Pull Request #25028 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20250619175533/https://github.com/python/cpython/pull/25028
Skip to content

Clarify glob logic a bit #25028

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

Closed
wants to merge 1 commit into from
Closed

Conversation

encukou
Copy link
Member

@encukou encukou commented Mar 26, 2021

This was flagged by a static analyzer as "possible copy-paste error"
(dirname vs. pathname), and it did take me a bit more time than
necessary to understand why this code is correct.
Mentioning the os.path.split behavior this relies on in a comment
should make it clearer.

Code is changed to work on pathname to make it clear that
we're checking the same thing as in the preceding branch.
In this case it is the same as dirname, except for a trailing
slash which is irrelevant for _isdir.

It took some more time than necessary to understand why this
code is correct. Mentioning the os.path.split behavior this
relies on in a comment should make it clearer.

Code is changed to work on "pathname" to make it clear that
we're checking the same thing as in the preceding branch.
In this case it is the same as dirname, except for a trailing
slash which is irrelevant for _isdir.
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 26, 2021
@nightlark
Copy link
Contributor

I'm very new to looking at the Python codebase and trying to understand what is going -- if I came across this function I'd find it easier to understand what is happening with these changes.

The comment about patterns ending with a slash also makes more sense by using pathname in the comparison rather than dirname.

@erlend-aasland
Copy link
Contributor

The PR title does not reflect the actual change; in addition to clarifying the glob logic, you're also changing parts of the logic. I believe this does not qualify for the skip issue label, even though the change in logic is probably trivial and correct.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Please add a test. It should fail with unpatched code and pass successfully with patched code.

Add a NEWS entry.

And please open an issue on the bug tracker for discussion.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@nightlark
Copy link
Contributor

nightlark commented Jan 10, 2022 •

Please add a test. It should fail with unpatched code and pass successfully with patched code.

@serhiy-storchaka this request has me a bit puzzled -- if I'm understanding the changed code correctly the functionality should be identical to what it was before, meaning you're asking for the impossible by wanting a test that fails with the unpatched code and passes with the patched code.

Unless you're seeing a corner case that this change has fixed, shouldn't it be that any tests using this function should all pass with both the unpatched code and patched code to demonstrate that no regression has taken place?

@serhiy-storchaka
Copy link
Member

If there is no difference, we do not need this change.

There is as risk of introducing a regression. I am not sure that os.stat('dirname/') works on all platforms. It may fail on some rare platforms for which we do not have buildbots.

@nightlark
Copy link
Contributor

nightlark commented Jan 18, 2022 •

There is as risk of introducing a regression. I am not sure that os.stat('dirname/') works on all platforms. It may fail on some rare platforms for which we do not have buildbots.

By that same logic, we also can't be sure os.stat('dirname') works on all platforms. Worse would be if some rare platforms only like a trailing slash, and others never want the trailing slash -- its more or less pointless to speculate about this, so testing more is the only thing we can do. What are some rare platforms you'd want tested that don't currently have buildbots?

@serhiy-storchaka
Copy link
Member

If I remember correctly, on some commercial Unix either stat() or open() did not work with a path ending with a slash. Even if I misremembered, there is no need of changing a working code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants