Skip to content

Fix hash() and __eq__() for File object #14573

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DaanDeMeyer
Copy link
Contributor

Two File objects should compare equal if their combined subdir and fname reference the same path. Currently they don't, so let's fix that.

This fixes extract_objects() when called with files() from a different directory than where the original sources were created.

Two File objects should compare equal if their combined subdir and
fname reference the same path. Currently they don't, so let's fix
that.

This fixes extract_objects() when called with files() from a different
directory than where the original sources were created.
@DaanDeMeyer DaanDeMeyer requested a review from jpakkane as a code owner May 8, 2025 08:07
@bonzini
Copy link
Collaborator

bonzini commented May 8, 2025

This fixes extract_objects() when called with files() from a different directory than where the original sources were created.

Can you add a testcase (or more likely extend an existing one)?

return (self.fname, self.subdir, self.is_built) == (other.fname, other.subdir, other.is_built)
if self.is_built != other.is_built:
return False
spath = os.path.join(self.subdir, self.fname)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For performance it's best to cache the result of os.path.join, after all you already compute it at __init__ time.

@bonzini bonzini added the bug label May 8, 2025
@dcbaker
Copy link
Member

dcbaker commented May 8, 2025

I tried to fix this once and ran into weird corner cases that I don't remember now. JFYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants