New submission from Nikita Sobolev <m...@sobolevn.me>:

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.

----------
assignee: sobolevn
components: Library (Lib)
messages: 410136
nosy: asvetlov, eric.araujo, sobolevn
priority: normal
severity: normal
status: open
title: Simplify `for` loop in `.close()` method in `asyncio/windows_events`
type: behavior
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46310>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to