Skip to content

Commit

Permalink
Harmonize Projection.__iter__ and .__len__ and avoid unnecessary copy…
Browse files Browse the repository at this point in the history
… to tuple for len.
  • Loading branch information
jaraco committed Mar 28, 2023
1 parent bf03fa4 commit c160d00
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jaraco/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ def __getitem__(self, key):
raise KeyError(key)
return self._space[key]

def _keys_resolved(self):
return set(self._keys).intersection(self._space)

def __iter__(self):
return iter(set(self._keys).intersection(self._space))
return iter(self._keys_resolved())

def __len__(self):
return len(tuple(iter(self)))
return len(self._keys_resolved())


class DictFilter(collections.abc.Mapping):
Expand Down

0 comments on commit c160d00

Please sign in to comment.