mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
delegate '__nonzero__' to '__bool__' for py2/py3 compatibility in one source. #1350
This commit is contained in:
parent
956d6286bf
commit
75e22ba522
@ -54,9 +54,10 @@ class DefDict(dict):
|
|||||||
return dict.__getitem__(self, key)
|
return dict.__getitem__(self, key)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return self.default
|
return self.default
|
||||||
def __nonzero__(self):
|
def __bool__(self):
|
||||||
# docutils check "if option_spec"
|
# docutils check "if option_spec"
|
||||||
return True
|
return True
|
||||||
|
__nonzero__ = __bool__ # for python2 compatibility
|
||||||
|
|
||||||
identity = lambda x: x
|
identity = lambda x: x
|
||||||
|
|
||||||
|
@ -60,8 +60,9 @@ class _TranslationProxy(UserString, object):
|
|||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
return key in self.data
|
return key in self.data
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __bool__(self):
|
||||||
return bool(self.data)
|
return bool(self.data)
|
||||||
|
__nonzero__ = __bool__ # for python2 compatibility
|
||||||
|
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return dir(text_type)
|
return dir(text_type)
|
||||||
|
@ -246,7 +246,7 @@ class Element(object):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._children)
|
return len(self._children)
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __bool__(self):
|
||||||
import warnings
|
import warnings
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"The behavior of this method will change in future versions. "
|
"The behavior of this method will change in future versions. "
|
||||||
@ -254,6 +254,7 @@ class Element(object):
|
|||||||
FutureWarning
|
FutureWarning
|
||||||
)
|
)
|
||||||
return len(self._children) != 0 # emulate old behaviour
|
return len(self._children) != 0 # emulate old behaviour
|
||||||
|
__nonzero__ = __bool__ # for python2 compatibility
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns the given subelement.
|
# Returns the given subelement.
|
||||||
|
Loading…
Reference in New Issue
Block a user