summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-12-16 23:13:02 +0900
committerGitHub <noreply@github.com>2018-12-16 23:13:02 +0900
commit36b7a2d6a4473ba81313a61c8aef6dac40f0a7af (patch)
tree032e16a9d5cf933bc840010d0a99947b16c7a72e
parent7bdbf50ee9ab8fe73174b3b38d38f77f42e69b0c (diff)
parent048cfb5e0ade34fef722e8f6529463d546ebf4ab (diff)
downloadsphinx-git-36b7a2d6a4473ba81313a61c8aef6dac40f0a7af.tar.gz
Merge pull request #5792 from tk0miya/deprecate_UnicodeMixin
Deprecate UnicodeMixin
-rw-r--r--CHANGES1
-rw-r--r--doc/extdev/index.rst5
-rw-r--r--sphinx/domains/cpp.py23
-rw-r--r--sphinx/ext/napoleon/docstring.py5
-rw-r--r--sphinx/locale/__init__.py4
-rw-r--r--sphinx/util/pycompat.py8
6 files changed, 26 insertions, 20 deletions
diff --git a/CHANGES b/CHANGES
index f2e9eed81..e7fdd8024 100644
--- a/CHANGES
+++ b/CHANGES
@@ -70,6 +70,7 @@ Deprecated
* ``sphinx.util.osutil.ENOENT``
* ``sphinx.util.osutil.walk()``
* ``sphinx.util.PeekableIterator``
+* ``sphinx.util.pycompat.UnicodeMixin``
* ``sphinx.util.pycompat.u``
* ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()``
* ``sphinx.writers.latex.TextTranslator._make_visit_admonition()``
diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst
index 3de9dcd10..24afdadf7 100644
--- a/doc/extdev/index.rst
+++ b/doc/extdev/index.rst
@@ -222,6 +222,11 @@ The following is a list of deprecated interfaces.
- 4.0
- ``os.walk()``
+ * - ``sphinx.util.pycompat.UnicodeMixin``
+ - 2.0
+ - 4.0
+ - N/A
+
* - ``sphinx.util.pycompat.u``
- 2.0
- 4.0
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 3d2c144f6..40dfd5df9 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -26,7 +26,6 @@ from sphinx.util import logging
from sphinx.util.docfields import Field, GroupedField
from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_refnode
-from sphinx.util.pycompat import UnicodeMixin
if False:
@@ -564,28 +563,28 @@ _id_explicit_cast = {
}
-class NoOldIdError(UnicodeMixin, Exception):
+class NoOldIdError(Exception):
# Used to avoid implementing unneeded id generation for old id schmes.
def __init__(self, description=""):
# type: (str) -> None
self.description = description
- def __unicode__(self):
+ def __str__(self):
# type: () -> str
return self.description
-class DefinitionError(UnicodeMixin, Exception):
+class DefinitionError(Exception):
def __init__(self, description):
# type: (str) -> None
self.description = description
- def __unicode__(self):
+ def __str__(self):
# type: () -> str
return self.description
-class _DuplicateSymbolError(UnicodeMixin, Exception):
+class _DuplicateSymbolError(Exception):
def __init__(self, symbol, declaration):
# type: (Symbol, Any) -> None
assert symbol
@@ -593,12 +592,12 @@ class _DuplicateSymbolError(UnicodeMixin, Exception):
self.symbol = symbol
self.declaration = declaration
- def __unicode__(self):
+ def __str__(self):
# type: () -> str
return "Internal C++ duplicate symbol error:\n%s" % self.symbol.dump(0)
-class ASTBase(UnicodeMixin):
+class ASTBase:
def __eq__(self, other):
# type: (Any) -> bool
if type(self) is not type(other):
@@ -622,7 +621,7 @@ class ASTBase(UnicodeMixin):
# type: (Callable[[Any], str]) -> str
raise NotImplementedError(repr(self))
- def __unicode__(self):
+ def __str__(self):
# type: () -> str
return self._stringify(lambda ast: text_type(ast))
@@ -789,7 +788,7 @@ class ASTNumberLiteral(ASTBase):
signode.append(nodes.Text(txt, txt))
-class UnsupportedMultiCharacterCharLiteral(UnicodeMixin, Exception):
+class UnsupportedMultiCharacterCharLiteral(Exception):
def __init__(self, decoded):
self.decoded = decoded
@@ -1497,9 +1496,9 @@ class ASTIdentifier(ASTBase):
else:
return text_type(len(self.identifier)) + self.identifier
- # and this is where we finally make a difference between __unicode__ and the display string
+ # and this is where we finally make a difference between __str__ and the display string
- def __unicode__(self):
+ def __str__(self):
# type: () -> str
return self.identifier
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index a611d4267..c150fc552 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -17,7 +17,6 @@ from functools import partial
from sphinx.ext.napoleon.iterators import modify_iter
from sphinx.locale import _
-from sphinx.util.pycompat import UnicodeMixin
if False:
# For type annotation
@@ -39,7 +38,7 @@ _enumerated_list_regex = re.compile(
r'(?(paren)\)|\.)(\s+\S|\s*$)')
-class GoogleDocstring(UnicodeMixin):
+class GoogleDocstring:
"""Convert Google style docstrings to reStructuredText.
Parameters
@@ -177,7 +176,7 @@ class GoogleDocstring(UnicodeMixin):
self._parse()
- def __unicode__(self):
+ def __str__(self):
# type: () -> str
"""Return the parsed docstring in reStructuredText format.
diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py
index 162a2f0e4..9e78879d0 100644
--- a/sphinx/locale/__init__.py
+++ b/sphinx/locale/__init__.py
@@ -80,10 +80,6 @@ class _TranslationProxy(UserString):
# type: () -> str
return str(self.data)
- def __unicode__(self):
- # type: () -> str
- return text_type(self.data)
-
def __add__(self, other): # type: ignore
# type: (str) -> str
return self.data + other
diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py
index 4190f44ed..d0b3443b5 100644
--- a/sphinx/util/pycompat.py
+++ b/sphinx/util/pycompat.py
@@ -10,12 +10,14 @@
"""
import sys
+import warnings
from html import escape as htmlescape # NOQA
from io import TextIOWrapper # NOQA
from textwrap import indent # NOQA
from six import text_type
+from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.locale import __
from sphinx.util import logging
@@ -68,9 +70,13 @@ def convert_with_2to3(filepath):
class UnicodeMixin:
"""Mixin class to handle defining the proper __str__/__unicode__
- methods in Python 2 or 3."""
+ methods in Python 2 or 3.
+ .. deprecated:: 2.0
+ """
def __str__(self):
+ warnings.warn('UnicodeMixin is deprecated',
+ RemovedInSphinx40Warning, stacklevel=2)
return self.__unicode__()