FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-37953:Improve ForwardRef equality checks by hongweipeng · Pull Request #15628 · python/cpython · GitHub

Repository navigation

bpo-37953:Improve ForwardRef equality checks - #15628

Closed
hongweipeng wants to merge 4 commits into
python:masterfrom
hongweipeng:issue37953_forwardref_equal
Closed

hongweipeng wants to merge 4 commits into
python:masterfrom
hongweipeng:issue37953_forwardref_equal

Conversation

hongweipeng commented Aug 31, 2019 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

brandtbucher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks like a good change. I found one optimization that can be made, below.

Can you also add regression tests as well?

Comment thread Lib/typing.py Outdated
if p not in new_params:
new_params.append(p)
params = new_params
return tuple(params)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This whole bit can be sped up by just replacing it with:

return tuple(dict.fromkeys(params))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks, I will add some tests. By the way, params is a list, tuple(dict.fromkeys(params)) seems not faster than tuple(params), I think it would be better to keep tuple(params):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry, I should have been clearer! I meant replacing this whole list + loop bit with that one line. dict.fromkeys is a nice shortcut to remove duplicates while preserving order.

brandtbucher Sep 1, 2019 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah... I see now. You're trying to avoid the (broken) hashing.

I don't know how I feel about that. I think hashing should be fixed rather than just sidestepped here, since it's so tied to equality. At this point I'm actually in favor of a hybrid approach: combining your fix for __eq__ and the other PR #15400’s fix for __hash__.

@gvanrossum and @ilevkivskyi, thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@hongweipeng you can revert your most recent commit (3676a50, “code review”). My comment was misguided!

Comment thread Lib/typing.py
params = new_params
assert not all_params, all_params
return tuple(params)
return tuple(dict.fromkeys(params))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

TBH this looks like a hack. If at some point we would make sets ordered the same way as dicts are, it would be good to update the code, but currently I think I like the old way more.

Copy link
Copy Markdown
Member

See also my comment #15400 (comment) in the other PR.

Copy link
Copy Markdown
Contributor Author

PR #15650 is better.

hongweipeng closed this Sep 2, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

5 participants


Back | FazBrowse Home | New Git URL