GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-77753: Add hash examples for set/dict by slateny · Pull Request #92549 · python/cpython

Conversation

@slateny

@slateny slateny commented May 9, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

#77753

https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset

Depended by #91499

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@slateny
Add hash examples for set/dict
e680c74
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir awaiting review labels May 9, 2022
@slateny slateny added skip news needs backport to 3.9 needs backport to 3.11 only security fixes and removed needs backport to 3.9 labels May 9, 2022
AlexWaygood
AlexWaygood reviewed May 9, 2022
View reviewed changes
Comment thread Doc/library/stdtypes.rst
>>> d = {False: 'false'}
>>> d[0] = 0
>>> d
{False: 0}

@AlexWaygood AlexWaygood May 9, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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'}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Fidget-Spinner
Fidget-Spinner reviewed May 9, 2022
View reviewed changes
Comment thread Doc/library/stdtypes.rst
Note that as long as the objects have the same hash values, they are seen as
equivalent by sets::

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

@Fidget-Spinner Fidget-Spinner May 9, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood and kumaraditya303 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
serhiy-storchaka
serhiy-storchaka reviewed May 9, 2022
View reviewed changes
Comment thread Doc/library/stdtypes.rst
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::

@serhiy-storchaka serhiy-storchaka May 9, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/stdtypes.rst
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::

@serhiy-storchaka serhiy-storchaka May 9, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Same as above.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
serhiy-storchaka requested a review from rhettinger May 9, 2022 14:30
@rhettinger rhettinger added the DO-NOT-MERGE label May 9, 2022
@rhettinger

rhettinger commented May 9, 2022

Copy link
Copy Markdown
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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhettinger rhettinger closed this May 9, 2022
@slateny

slateny commented May 10, 2022

Copy link
Copy Markdown
Contributor Author

@rhettinger I understand that the examples on hashing isn't as useful, but does the dict 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slateny slateny mentioned this pull request Jul 12, 2022
Better document mixed-type comparison of set items, dict keys #77753
Closed
@slateny
slateny deleted the s/stdtypes branch October 20, 2022 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@Fidget-Spinner Fidget-Spinner Fidget-Spinner left review comments
@AlexWaygood AlexWaygood AlexWaygood left review comments
@rhettinger rhettinger Awaiting requested review from rhettinger

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review DO-NOT-MERGE docs Documentation in the Doc dir needs backport to 3.11 only security fixes skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@slateny @rhettinger @serhiy-storchaka @Fidget-Spinner @AlexWaygood @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.