This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Simplify `for` loop in `.close()` method in `asyncio/windows_events`
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: sobolevn Nosy List: asvetlov, eric.araujo, kumaraditya, sobolevn, yselivanov
Priority: normal Keywords: patch

Created on 2022-01-09 09:11 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30334 merged sobolevn, 2022-01-09 09:11
Messages (2)
msg410136 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-09 09:11
This line https://github.com/python/cpython/blob/3d11c1b8b49800c5c4c295953cc3abf577f6065a/Lib/asyncio/windows_events.py#L842 uses `.items()`, but the key seems unsused.

It would be better to use `.values()` there.

1. It is slightly faster, very generic benchmark:

```
import timeit
cache = {i: (i, i + 1, None, f'a{i}') for i in range(1000)}
timeit.timeit('list(cache.items())', number=1000, globals=locals())
# 0.18165644304826856
timeit.timeit('list(cache.values())', number=1000, globals=locals())
# 0.04786261299159378
```

2. It is more readable, because unused variables are not created

And since it does not break anything, I think it is safe to refactor.
msg410287 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-01-11 10:52
New changeset fc75bfb8be8494e22123f2c14d1ab497c77cc22d by Nikita Sobolev in branch 'main':
bpo-46310: simplify `for` loop in `asyncio/windows_events` (GH-30334)
https://github.com/python/cpython/commit/fc75bfb8be8494e22123f2c14d1ab497c77cc22d
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90468
2022-01-11 10:52:05asvetlovsetmessages: + msg410287
2022-01-11 10:51:58asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-10 06:53:54kumaradityasetnosy: + yselivanov, kumaraditya
components: + asyncio, - Library (Lib)
2022-01-09 09:11:51sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28701
2022-01-09 09:11:22sobolevncreate