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

gh-77753: Add hash examples for set/dict#92549

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

Closed
slateny wants to merge1 commit intopython:mainfromslateny:s/stdtypes

Conversation

slateny
Copy link
Contributor

@slatenyslateny commentedMay 9, 2022
edited
Loading

AlexWaygood reacted with thumbs up emoji
@bedevere-botbedevere-bot added docsDocumentation in the Doc dir awaiting review labelsMay 9, 2022
@slatenyslateny added skip news needs backport to 3.9only security fixes needs backport to 3.10only security fixes needs backport to 3.11only security fixes and removed needs backport to 3.9only security fixes needs backport to 3.10only security fixes labelsMay 9, 2022
>>> d = {False: 'false'}
>>> d[0] = 0
>>> d
{False: 0}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{False: 0}
{False: 0}
>>>{1:'a',True:'b'}
{1: 'b'}

Note that as long as the objects have the same hash values, they are seen as
equivalent by sets::

>>> {0, True, False, 1}

Choose a reason for hiding this comment

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

Could you please add some of the types Terry listed in the issue too? I was frankly surprised at them (especially the Decimal and Fractions with the same hash value).
Maybe this would help:

Suggested change
>>>{0,True,False,1}
>>>{0,True,False,1,0.0,1.0}

AlexWaygood and kumaraditya303 reacted with thumbs up emoji
Comment on lines +4184 to +4185
Note that as long as the objects have the same hash values, they are seen as
equivalent by sets::

Choose a reason for hiding this comment

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

It is not true.

>>> hash(1) == hash(2**61)True>>> {1, 2**61}{1, 2305843009213693952}

Comment on lines +4392 to +4393
This also means if two keys have the same hash values, they will map to the same
entry in the dictionary::

Choose a reason for hiding this comment

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

Same as above.

@rhettinger
Copy link
Contributor

Besides making two flat-out incorrect statements, I also don't think this is very useful.

The examples are cute but aren't relevant to most users of dicts and sets. Also, it isn't the sets or dicts themselves that give rise to these examples; instead, it is that numbers were intentionally designed to support cross-type equality comparisons and to follow the rule that equal values should have the same hashes. This is documented elsewhere.

Thanks for the suggestion, but I'm marking it is closed as a low quality edit.

serhiy-storchaka reacted with thumbs up emoji

@slateny
Copy link
ContributorAuthor

@rhettinger I understand that the examples on hashing isn't as useful, but does thedict example about same keys but different values not warrant at least something? There seems to be twoish open issues on this, and I don't think the behavior's exactly intuitive. If it is this behavior that's documented somewhere, then I reckon that some sort of link or reference would help.

When you mark it closed due to low quality, is it due to examples not thorough enough, wording too short, or something else? I would like to improve the docs so knowing what exactly can be changed other than the incorrectness would be helpful to me.

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

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@Fidget-SpinnerFidget-SpinnerFidget-Spinner left review comments

@AlexWaygoodAlexWaygoodAlexWaygood left review comments

@rhettingerrhettingerAwaiting requested review from rhettinger

Assignees
No one assigned
Labels
awaiting reviewDO-NOT-MERGEdocsDocumentation in the Doc dirneeds backport to 3.11only security fixesskip news
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@slateny@rhettinger@serhiy-storchaka@Fidget-Spinner@AlexWaygood@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp