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

bpo-43475: Fix worst case collision behavior for NaN instances#25493

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

Merged
rhettinger merged 6 commits intopython:masterfromrhettinger:nan_hash
Apr 22, 2021

Conversation

@rhettinger
Copy link
Contributor

@rhettingerrhettinger commentedApr 21, 2021
edited by bedevere-bot
Loading

@rhettingerrhettinger removed the request for review fromtiranApril 21, 2021 03:38
@rhettingerrhettinger added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelApr 21, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@rhettinger for commit056a4f7 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelApr 21, 2021
@rhettingerrhettinger added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelApr 21, 2021
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@rhettinger for commit9f3f9e9 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelApr 21, 2021
@rhettingerrhettinger merged commita07da09 intopython:masterApr 22, 2021
@realead
Copy link

Is my understanding right, that this PR would break the following code:

import mathclass A:    def __init__(self, a):        self.a=a    def __hash__(self):        return hash(self.a)    def __eq__(self, other):        if(math.isnan(self.a) and math.isnan(other.a)):            return True        return self.a == other.a    def __repr__(self):        return str(self.a)        set([A(float("nan")), A(float("nan"))])  # result: {nan}

I.e. when somebody tries to wrap Float and change__eq__ in such a way, that all float-nans will be equivalent?

With this PR, the chances are high, that the result will be{nan, nan}, as hashes from both objects will be different.

Until now, it was clear - don't put nans into set/dict because the default "="-relation for floats isn't an equivalence relation. People worked around this by redefining the "="-relation and didn't so for hash function because until now "a,b - nans => hash(a)=hash(b)" was given.


I think the intuitive behavior forset([float("nan"), float("nan")] is{nan} and not{nan, nan}. Given howPy_EQ is defined for floats, this is not possible. Maybe there is need for a newPy_EQ_FOR_HASH comparator, which would be used in hashset/hashdict and be more or less the same asPy_EQ but would yield true fornan==nan.

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

Reviewers

@mdickinsonmdickinsonAwaiting requested review from mdickinson

@tim-onetim-oneAwaiting requested review from tim-one

Assignees

No one assigned

Labels

performancePerformance or resource usage

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@rhettinger@bedevere-bot@realead@the-knights-who-say-ni

[8]ページ先頭

©2009-2025 Movatter.jp