Merge pull request #5792 from tk0miya/deprecate_UnicodeMixin

Deprecate UnicodeMixin
This commit is contained in:
Takeshi KOMIYA 2018-12-16 23:13:02 +09:00 committed by GitHub
commit 36b7a2d6a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 20 deletions

View File

@ -70,6 +70,7 @@ Deprecated
* ``sphinx.util.osutil.ENOENT`` * ``sphinx.util.osutil.ENOENT``
* ``sphinx.util.osutil.walk()`` * ``sphinx.util.osutil.walk()``
* ``sphinx.util.PeekableIterator`` * ``sphinx.util.PeekableIterator``
* ``sphinx.util.pycompat.UnicodeMixin``
* ``sphinx.util.pycompat.u`` * ``sphinx.util.pycompat.u``
* ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()`` * ``sphinx.writers.latex.LaTeXTranslator.babel_defmacro()``
* ``sphinx.writers.latex.TextTranslator._make_visit_admonition()`` * ``sphinx.writers.latex.TextTranslator._make_visit_admonition()``

View File

@ -222,6 +222,11 @@ The following is a list of deprecated interfaces.
- 4.0 - 4.0
- ``os.walk()`` - ``os.walk()``
* - ``sphinx.util.pycompat.UnicodeMixin``
- 2.0
- 4.0
- N/A
* - ``sphinx.util.pycompat.u`` * - ``sphinx.util.pycompat.u``
- 2.0 - 2.0
- 4.0 - 4.0

View File

@ -26,7 +26,6 @@ from sphinx.util import logging
from sphinx.util.docfields import Field, GroupedField from sphinx.util.docfields import Field, GroupedField
from sphinx.util.docutils import SphinxDirective from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_refnode from sphinx.util.nodes import make_refnode
from sphinx.util.pycompat import UnicodeMixin
if False: 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. # Used to avoid implementing unneeded id generation for old id schmes.
def __init__(self, description=""): def __init__(self, description=""):
# type: (str) -> None # type: (str) -> None
self.description = description self.description = description
def __unicode__(self): def __str__(self):
# type: () -> str # type: () -> str
return self.description return self.description
class DefinitionError(UnicodeMixin, Exception): class DefinitionError(Exception):
def __init__(self, description): def __init__(self, description):
# type: (str) -> None # type: (str) -> None
self.description = description self.description = description
def __unicode__(self): def __str__(self):
# type: () -> str # type: () -> str
return self.description return self.description
class _DuplicateSymbolError(UnicodeMixin, Exception): class _DuplicateSymbolError(Exception):
def __init__(self, symbol, declaration): def __init__(self, symbol, declaration):
# type: (Symbol, Any) -> None # type: (Symbol, Any) -> None
assert symbol assert symbol
@ -593,12 +592,12 @@ class _DuplicateSymbolError(UnicodeMixin, Exception):
self.symbol = symbol self.symbol = symbol
self.declaration = declaration self.declaration = declaration
def __unicode__(self): def __str__(self):
# type: () -> str # type: () -> str
return "Internal C++ duplicate symbol error:\n%s" % self.symbol.dump(0) return "Internal C++ duplicate symbol error:\n%s" % self.symbol.dump(0)
class ASTBase(UnicodeMixin): class ASTBase:
def __eq__(self, other): def __eq__(self, other):
# type: (Any) -> bool # type: (Any) -> bool
if type(self) is not type(other): if type(self) is not type(other):
@ -622,7 +621,7 @@ class ASTBase(UnicodeMixin):
# type: (Callable[[Any], str]) -> str # type: (Callable[[Any], str]) -> str
raise NotImplementedError(repr(self)) raise NotImplementedError(repr(self))
def __unicode__(self): def __str__(self):
# type: () -> str # type: () -> str
return self._stringify(lambda ast: text_type(ast)) return self._stringify(lambda ast: text_type(ast))
@ -789,7 +788,7 @@ class ASTNumberLiteral(ASTBase):
signode.append(nodes.Text(txt, txt)) signode.append(nodes.Text(txt, txt))
class UnsupportedMultiCharacterCharLiteral(UnicodeMixin, Exception): class UnsupportedMultiCharacterCharLiteral(Exception):
def __init__(self, decoded): def __init__(self, decoded):
self.decoded = decoded self.decoded = decoded
@ -1497,9 +1496,9 @@ class ASTIdentifier(ASTBase):
else: else:
return text_type(len(self.identifier)) + self.identifier 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 # type: () -> str
return self.identifier return self.identifier

View File

@ -17,7 +17,6 @@ from functools import partial
from sphinx.ext.napoleon.iterators import modify_iter from sphinx.ext.napoleon.iterators import modify_iter
from sphinx.locale import _ from sphinx.locale import _
from sphinx.util.pycompat import UnicodeMixin
if False: if False:
# For type annotation # For type annotation
@ -39,7 +38,7 @@ _enumerated_list_regex = re.compile(
r'(?(paren)\)|\.)(\s+\S|\s*$)') r'(?(paren)\)|\.)(\s+\S|\s*$)')
class GoogleDocstring(UnicodeMixin): class GoogleDocstring:
"""Convert Google style docstrings to reStructuredText. """Convert Google style docstrings to reStructuredText.
Parameters Parameters
@ -177,7 +176,7 @@ class GoogleDocstring(UnicodeMixin):
self._parse() self._parse()
def __unicode__(self): def __str__(self):
# type: () -> str # type: () -> str
"""Return the parsed docstring in reStructuredText format. """Return the parsed docstring in reStructuredText format.

View File

@ -80,10 +80,6 @@ class _TranslationProxy(UserString):
# type: () -> str # type: () -> str
return str(self.data) return str(self.data)
def __unicode__(self):
# type: () -> str
return text_type(self.data)
def __add__(self, other): # type: ignore def __add__(self, other): # type: ignore
# type: (str) -> str # type: (str) -> str
return self.data + other return self.data + other

View File

@ -10,12 +10,14 @@
""" """
import sys import sys
import warnings
from html import escape as htmlescape # NOQA from html import escape as htmlescape # NOQA
from io import TextIOWrapper # NOQA from io import TextIOWrapper # NOQA
from textwrap import indent # NOQA from textwrap import indent # NOQA
from six import text_type from six import text_type
from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.locale import __ from sphinx.locale import __
from sphinx.util import logging from sphinx.util import logging
@ -68,9 +70,13 @@ def convert_with_2to3(filepath):
class UnicodeMixin: class UnicodeMixin:
"""Mixin class to handle defining the proper __str__/__unicode__ """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): def __str__(self):
warnings.warn('UnicodeMixin is deprecated',
RemovedInSphinx40Warning, stacklevel=2)
return self.__unicode__() return self.__unicode__()