Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add __bool__ operator #755

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/rez/package_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def __and__(self, other):
def __nonzero__(self):
return bool(self._excludes)

__bool__ = __nonzero__ # py3 compat

@cached_property
def cost(self):
"""Get the approximate cost of this filter.
Expand Down Expand Up @@ -271,6 +273,8 @@ def to_pod(self):
def __nonzero__(self):
return any(self.filters)

__bool__ = __nonzero__ # py3 compat

def __str__(self):
filters = sorted(self.filters, key=lambda x: (x.cost, str(x)))
return str(tuple(filters))
Expand Down
2 changes: 2 additions & 0 deletions src/rez/rex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,8 @@ def __repr__(self):
def __nonzero__(self):
return bool(self.value())

__bool__ = __nonzero__ # py3 compat

def __eq__(self, value):
if isinstance(value, EnvironmentVariable):
value = value.value()
Expand Down
4 changes: 3 additions & 1 deletion src/rez/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def pr(self, txt='', *args):
print(txt % args, file=self.buf)

def __nonzero__(self):
return self.verbosity
return self.verbosity > 0

__bool__ = __nonzero__ # py3 compat


class SolverState(object):
Expand Down
2 changes: 1 addition & 1 deletion src/rez/utils/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


# Update this value to version up Rez. Do not place anything else in this file.
_rez_version = "2.47.3"
_rez_version = "2.47.4"


# Copyright 2013-2016 Allan Johns.
Expand Down
2 changes: 2 additions & 0 deletions src/rez/utils/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __call__(self, msg, *nargs):
def __nonzero__(self):
return bool(self.printer_function)

__bool__ = __nonzero__ # py3 compat


@contextmanager
def log_duration(printer, msg):
Expand Down
7 changes: 6 additions & 1 deletion src/rez/utils/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class Client(object):
- ability to cache None.
"""
class _Miss(object):
def __nonzero__(self): return False
def __nonzero__(self):
return False
__bool__ = __nonzero__ # py3 compat

miss = _Miss()

logger = config.debug_printer("memcache")
Expand All @@ -50,6 +53,8 @@ def __init__(self, servers, debug=False):
def __nonzero__(self):
return bool(self.servers)

__bool__ = __nonzero__ # py3 compat

@property
def client(self):
"""Get the native memcache client.
Expand Down
2 changes: 2 additions & 0 deletions src/rez/vendor/version/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ def __nonzero__(self):
"""The empty version equates to False."""
return bool(self.tokens)

__bool__ = __nonzero__ # py3 compat

def __eq__(self, other):
return isinstance(other, Version) and self.tokens == other.tokens

Expand Down