Skip to content

Commit

Permalink
disable lru_cache for a function
Browse files Browse the repository at this point in the history
not return the same iterator
  • Loading branch information
frostming committed Oct 1, 2019
1 parent ac22ce5 commit 66e57d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
54 changes: 32 additions & 22 deletions src/passa/internals/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from backports.functools_lru_cache import lru_cache


def _ensure_marker(marker):
if not isinstance(marker, _Marker):
return _Marker(str(marker))
def _ensure_marker(marker, cls=_Marker):
if not isinstance(marker, cls):
return cls(str(marker))
return marker


Expand Down Expand Up @@ -260,26 +260,36 @@ def __init__(self, marker=None):
super(Marker, self).__init__(marker)

def __and__(self, other):
other = _ensure_marker(other)
if not self._markers or self == other:
return type(self)(str(other))
lhs, rhs = str(self), str(other)
# When combining markers with 'and', wrap the part with parentheses
# if there exist 'or's.
if 'or' in self._markers:
lhs = '({})'.format(str(self))
if 'or' in other._markers:
rhs = '({})'.format(str(other))
new_marker = type(self)("{} and {}".format(lhs, rhs))
return new_marker
other = _ensure_marker(other, Marker)
if self == other:
marker_string = str(self)
elif not self:
marker_string = str(other)
elif not other:
marker_string = str(self)
else:
lhs, rhs = str(self), str(other)
# When combining markers with 'and', wrap the part with parentheses
# if there exist 'or's.
if 'or' in self._markers:
lhs = '({})'.format(str(self))
if 'or' in other._markers:
rhs = '({})'.format(str(other))
marker_string = "{} and {}".format(lhs, rhs)
return type(self)(marker_string)

def __or__(self, other):
other = _ensure_marker(other)
if not self._markers or self == other:
return type(self)(str(other))
# Just join parts with 'or' since it has the lowest priority.
new_marker = type(self)("{} or {}".format(str(self), str(other)))
return new_marker
other = _ensure_marker(other, Marker)
if self == other:
marker_string = str(self)
elif not self:
marker_string = str(other)
elif not other:
marker_string = str(self)
else:
# Just join parts with 'or' since it has the lowest priority.
marker_string = "{} or {}".format(str(self), str(other))
return type(self)(marker_string)

def __bool__(self):
return bool(self._markers)
Expand All @@ -296,4 +306,4 @@ def __eq__(self, other):
return self._markers == other._markers

def __lt__(self, other):
return self._markers < other._markers
return hash(self) < hash(other)
1 change: 0 additions & 1 deletion src/passa/internals/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def _get_specs(specset):
return result


@lru_cache(maxsize=128)
def _group_by_op(specs):
specs = [_get_specs(x) for x in list(specs)]
flattened = [(op, version) for spec in specs for op, version in spec]
Expand Down

0 comments on commit 66e57d0

Please sign in to comment.