Skip to content

gh-101346: compare and hash code objects by identity #103297

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 2 commits into from

Conversation

carljm
Copy link
Member

@carljm carljm commented Apr 5, 2023

This removes the complex, finicky, and unnecessary hash and comparison methods of code objects. As code objects change, these methods regularly become out of date and have to be updated to account for new fields. And as code objects have become more mutable with the specializing interpreter, it makes less sense to treat them as value types.

After this PR, code objects are hashed/equal solely by identity (the default behavior of Python objects), which is faster and simpler.

Given that "naturally occurring" code objects are in practice never equal to each other by the old rules anyway, this only impacts such artificial cases as code == code.replace() (which was previously true and is no longer true with this PR.)

Closes #101346.

@carljm carljm closed this Apr 6, 2023
@markshannon
Copy link
Member

markshannon commented Apr 6, 2023

@carljm Did you mean to close this? Just seen your comment on the issue.

@carljm
Copy link
Member Author

carljm commented Apr 6, 2023

@markshannon I did close it intentionally because I become unconvinced we should merge it. But I'm happy to reopen it if we reach a different conclusion.

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.

The hash and equals methods of code objects are large, complex and unnecessary.
3 participants