summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2014-05-01 20:14:19 +0900
committershimizukawa <shimizukawa@gmail.com>2014-05-01 20:14:19 +0900
commit6759ba4b68bda60626ebb1a69a0194de0b762485 (patch)
tree46aa7e3ee51a8e1741006d1c218a07ce8c288eb6
parent8802cbe037c7b90d04220865aa376020360e6226 (diff)
downloadsphinx-6759ba4b68bda60626ebb1a69a0194de0b762485.tar.gz
delegate '__nonzero__' to '__bool__' for py2/py3 compatibility in one source. #1350
-rw-r--r--sphinx/ext/autodoc.py3
-rw-r--r--sphinx/locale/__init__.py3
-rw-r--r--tests/etree13/ElementTree.py3
3 files changed, 6 insertions, 3 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 11b38d99..ab081097 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -54,9 +54,10 @@ class DefDict(dict):
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
diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py
index 75deac05..9332f474 100644
--- a/sphinx/locale/__init__.py
+++ b/sphinx/locale/__init__.py
@@ -60,8 +60,9 @@ class _TranslationProxy(UserString, object):
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)
diff --git a/tests/etree13/ElementTree.py b/tests/etree13/ElementTree.py
index 5342278c..25ec1e05 100644
--- a/tests/etree13/ElementTree.py
+++ b/tests/etree13/ElementTree.py
@@ -246,7 +246,7 @@ class Element(object):
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. "
@@ -254,6 +254,7 @@ class Element(object):
FutureWarning
)
return len(self._children) != 0 # emulate old behaviour
+ __nonzero__ = __bool__ # for python2 compatibility
##
# Returns the given subelement.