Skip to content

Commit

Permalink
Use set intersection len for DictFilter. Fixes #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 22, 2023
1 parent 617c1d2 commit bf03fa4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v3.9.0
======

``DictFilter.__len__`` no longer relies on the iterable. Improves
efficiency and fixes ``RecursionError`` on PyPy (#12).

v3.8.0
======

Expand Down
2 changes: 1 addition & 1 deletion jaraco/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __iter__(self):
return filter(self.include_keys.__contains__, self.dict.keys())

def __len__(self):
return len(list(self))
return len(self.include_keys & self.dict.keys())


def dict_map(function, dictionary):
Expand Down

0 comments on commit bf03fa4

Please sign in to comment.