Skip to content

Commit

Permalink
delegate '__nonzero__' to '__bool__' for py2/py3 compatibility in one…
Browse files Browse the repository at this point in the history
… source. #1350
  • Loading branch information
shimizukawa committed May 1, 2014
1 parent 956d628 commit 75e22ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion sphinx/ext/autodoc.py
Expand Up @@ -54,9 +54,10 @@ def __getitem__(self, key):
return dict.__getitem__(self, key)
except KeyError:
return self.default
def __nonzero__(self):
def __bool__(self):
# docutils check "if option_spec"
return True
__nonzero__ = __bool__ # for python2 compatibility

identity = lambda x: x

Expand Down
3 changes: 2 additions & 1 deletion sphinx/locale/__init__.py
Expand Up @@ -60,8 +60,9 @@ def encode(self, encoding=None, errors=None):
def __contains__(self, key):
return key in self.data

def __nonzero__(self):
def __bool__(self):
return bool(self.data)
__nonzero__ = __bool__ # for python2 compatibility

def __dir__(self):
return dir(text_type)
Expand Down
3 changes: 2 additions & 1 deletion tests/etree13/ElementTree.py
Expand Up @@ -246,14 +246,15 @@ def makeelement(self, tag, attrib):
def __len__(self):
return len(self._children)

def __nonzero__(self):
def __bool__(self):
import warnings
warnings.warn(
"The behavior of this method will change in future versions. "
"Use specific 'len(elem)' or 'elem is not None' test instead.",
FutureWarning
)
return len(self._children) != 0 # emulate old behaviour
__nonzero__ = __bool__ # for python2 compatibility

##
# Returns the given subelement.
Expand Down

0 comments on commit 75e22ba

Please sign in to comment.