Opened 6 years ago

Closed 6 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)

narrow.patch (13.0 KB ) - added by Дилян Палаузов 6 years ago.

Download all attachments as: .zip

Change History (7)

by Дилян Палаузов, 6 years ago

Attachment: narrow.patch added

comment:1 by Tim Graham, 6 years ago

Component: UncategorizedCore (Other)
Has patch: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

keys() is generally unneeded. Something like for 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 in debug.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.

comment:2 by Sergey Fedoseev, 6 years ago

Cc: Sergey Fedoseev added

comment:3 by Дилян Палаузов, 6 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.

in reply to:  3 comment:4 by Sergey Fedoseev, 6 years ago

Replying to Дилян Палаузов:

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.

In [2]: iter({})
Out[2]: <dict_keyiterator at 0x7fd09e6d3598>

In [3]: iter({}.keys())
Out[3]: <dict_keyiterator at 0x7fd09e6d3728>

comment:5 by Tim Graham, 6 years ago

Patch needs improvement: unset

comment:6 by GitHub <noreply@…>, 6 years ago

Resolution: fixed
Status: newclosed

In a862af38:

Fixed #28893 -- Removed unnecessary dict.items() calls.

Note: See TracTickets for help on using tickets.
Back to Top