Skip to content

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

Open
daandemeyer wants to merge 1 commit into
mesonbuild:masterfrom
daandemeyer:hash
Open

Fix hash() and __eq__() for File object#14573
daandemeyer wants to merge 1 commit into
mesonbuild:masterfrom
daandemeyer:hash

Conversation

@daandemeyer

Copy link
Copy Markdown
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

bonzini commented May 8, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

dcbaker commented May 8, 2025

Copy link
Copy Markdown
Member

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

@bonzini bonzini added this to the 1.11.3 milestone Jun 8, 2026
@bonzini bonzini modified the milestones: 1.11.3, 1.13 Jul 5, 2026
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