Skip to content

Commit 416c501

Browse files
committed
Use dict comprehensions instead of dict+zip
Dict comprehensions are more readable and faster: ❯ ./python -m timeit -s 'import types; c = dict(zip("abcdefghi", iter(types.CellType, None)))' 'dict(zip(c, map(id, c.values())))' 100000 loops, best of 5: 3.15 usec per loop ❯ ./python -m timeit -s 'import types; c = dict(zip("abcdefghi", iter(types.CellType, None)))' '{name: id(cell) for name, cell in c.items()}' 100000 loops, best of 5: 2.86 usec per loop
1 parent 094f0f8 commit 416c501

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/annotationlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ def __eq__(self, other):
281281
and self.__forward_is_class__ == other.__forward_is_class__
282282
# Two separate cells are always considered unequal in forward refs.
283283
and (
284-
dict(zip(self.__cell__, map(id, self.__cell__.values())))
285-
== dict(zip(other.__cell__, map(id, other.__cell__.values())))
284+
{name: id(cell) for name, cell in self.__cell__.items()}
285+
== {name: id(cell) for name, cell in other.__cell__.items()}
286286
if isinstance(self.__cell__, dict) and isinstance(other.__cell__, dict)
287287
else self.__cell__ is other.__cell__
288288
)

0 commit comments

Comments
 (0)