Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Optimise LiteralType.__eq__ and __hash__#20423

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
hauntsaninja wants to merge1 commit intopython:master
base:master
Choose a base branch
Loading
fromhauntsaninja:mypylit

Conversation

@hauntsaninja
Copy link
Collaborator

@hauntsaninjahauntsaninja commentedDec 16, 2025
edited
Loading

If I'm doing it right, this should be 1-2% on a profile I'm looking at

If I'm doing it right, this should be 2% on a profile I'm looking at
@github-actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

ifself._hash==-1:
self._hash=hash((self.value,self.fallback))
returnself._hash
returnhash(self.value)
Copy link
Member

Choose a reason for hiding this comment

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

Is this part actually safe? This will makeLiteral["foo"] andLiteral[b"foo"] have same hash (I don't remember why, but we always store the literal bytes value as a string).

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's alsoLiteral[0] vsLiteral[False], both 0 and False hash to zero IIRC

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

It's fine for hashes to collide and doesn't affect correctness. You just don't want too many values to collide because then some of your constant time operations become linear.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Only correctness requirement is that values that compare equal have the same hash

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ilevkivskyiilevkivskyiilevkivskyi left review comments

+1 more reviewer

@sterliakovsterliakovsterliakov left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@hauntsaninja@ilevkivskyi@sterliakov

[8]ページ先頭

©2009-2025 Movatter.jp