Opened 8 days ago

Closed 7 days ago

#28893 closed Cleanup/optimization (fixed)

Narrow dict.items() calls to .keys()/.items()

Reported by: Дилян Палаузов Owned by: nobody
Component: Core (Other) Version: master
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 Дилян Палаузов 8 days ago.

Download all attachments as: .zip

Change History (7)

Changed 8 days ago by Дилян Палаузов

Attachment: narrow.patch added

comment:1 Changed 8 days ago by Tim Graham

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 Changed 8 days ago by Sergey Fedoseev

Cc: Sergey Fedoseev added

comment:3 Changed 7 days ago by Дилян Палаузов

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 in reply to:  3 Changed 7 days ago by Sergey Fedoseev

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 Changed 7 days ago by Tim Graham

Patch needs improvement: unset

comment:6 Changed 7 days ago by GitHub <noreply@…>

Resolution: fixed
Status: newclosed

In a862af38:

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

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