Opened 7 years ago
Closed 7 years ago
#28893 closed Cleanup/optimization (fixed)
Narrow dict.items() calls to .keys()/.items()
Reported by: | Дилян Палаузов | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Sergey Fedoseev | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Attachments (1)
Change History (7)
by , 7 years ago
Attachment: | narrow.patch added |
---|
comment:1 by , 7 years ago
Component: | Uncategorized → Core (Other) |
---|---|
Has patch: | set |
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 7 years ago
Cc: | added |
---|
follow-up: 4 comment:3 by , 7 years ago
Yes, it is better not to apply the last snippet in debug.py.
I know that iterating over a dict:
and dict.keys():
is effectively the same, but while the later returns (an iterator of) a view, I don't know what the former returns and therefore whether both forms are really equivalent.
comment:4 by , 7 years ago
Replying to Дилян Палаузов:
I know that iterating over a
dict:
anddict.keys():
is effectively the same, but while the later returns (an iterator of) a view, I don't know what the former returns and therefore whether both forms are really equivalent.
In [2]: iter({}) Out[2]: <dict_keyiterator at 0x7fd09e6d3598> In [3]: iter({}.keys()) Out[3]: <dict_keyiterator at 0x7fd09e6d3728>
keys()
is generally unneeded. Something likefor name in tb_frame.f_locals
does an implicit keys; see 21046e77734278cea871dce922220bf29aa5b7b4. I guess you didn't test the patch as there's at least one mistake indebug.py
that broke things.By the way, is there something preventing you from submitting patches on GitHub? If it's only the knowledge of how to to do, we have a tutorial.