summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-05-06 19:29:40 (GMT)
committerGitHub <noreply@github.com>2019-05-06 19:29:40 (GMT)
commit96aeaec64738b730c719562125070a52ed570210 (patch)
treed68994f93014d081e9a441e7bf7dfda3aaadd402 /Lib
parent964663089547ca110199e23867b46b07ff4be88c (diff)
downloadcpython-96aeaec64738b730c719562125070a52ed570210.zip
cpython-96aeaec64738b730c719562125070a52ed570210.tar.gz
cpython-96aeaec64738b730c719562125070a52ed570210.tar.bz2
bpo-36793: Remove unneeded __str__ definitions. (GH-13081)
Classes that define __str__ the same as __repr__ can just inherit it from object.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pydecimal.py2
-rw-r--r--Lib/asyncore.py2
-rw-r--r--Lib/doctest.py3
-rw-r--r--Lib/email/charset.py4
-rw-r--r--Lib/http/client.py3
-rw-r--r--Lib/json/encoder.py4
-rw-r--r--Lib/logging/__init__.py4
-rw-r--r--Lib/sre_constants.py4
-rw-r--r--Lib/subprocess.py1
-rw-r--r--Lib/xmlrpc/client.py7
10 files changed, 8 insertions, 26 deletions
diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py
index 44ea5b4..c14d8ca 100644
--- a/Lib/_pydecimal.py
+++ b/Lib/_pydecimal.py
@@ -5631,8 +5631,6 @@ class _WorkRep(object):
def __repr__(self):
return "(%r, %r, %r)" % (self.sign, self.int, self.exp)
- __str__ = __repr__
-
def _normalize(op1, op2, prec = 0):
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 828f4d4..0e92be3 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -262,8 +262,6 @@ class dispatcher:
status.append(repr(self.addr))
return '<%s at %#x>' % (' '.join(status), id(self))
- __str__ = __repr__
-
def add_channel(self, map=None):
#self.log_info('adding channel %s' % self)
if map is None:
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 79d91a0..bf4889f 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -2300,7 +2300,7 @@ class DocTestCase(unittest.TestCase):
name = self._dt_test.name.split('.')
return "%s (%s)" % (name[-1], '.'.join(name[:-1]))
- __str__ = __repr__
+ __str__ = object.__str__
def shortDescription(self):
return "Doctest: " + self._dt_test.name
@@ -2399,7 +2399,6 @@ class DocFileCase(DocTestCase):
def __repr__(self):
return self._dt_test.filename
- __str__ = __repr__
def format_failure(self, err):
return ('Failed doctest test for %s\n File "%s", line 0\n\n%s'
diff --git a/Lib/email/charset.py b/Lib/email/charset.py
index ee56404..d3d759a 100644
--- a/Lib/email/charset.py
+++ b/Lib/email/charset.py
@@ -241,11 +241,9 @@ class Charset:
self.output_codec = CODEC_MAP.get(self.output_charset,
self.output_charset)
- def __str__(self):
+ def __repr__(self):
return self.input_charset.lower()
- __repr__ = __str__
-
def __eq__(self, other):
return str(self) == str(other).lower()
diff --git a/Lib/http/client.py b/Lib/http/client.py
index f71a062..82908eb 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -1419,8 +1419,7 @@ class IncompleteRead(HTTPException):
e = ''
return '%s(%i bytes read%s)' % (self.__class__.__name__,
len(self.partial), e)
- def __str__(self):
- return repr(self)
+ __str__ = object.__str__
class ImproperConnectionState(HTTPException):
pass
diff --git a/Lib/json/encoder.py b/Lib/json/encoder.py
index 2d7b898..c8c78b9 100644
--- a/Lib/json/encoder.py
+++ b/Lib/json/encoder.py
@@ -268,7 +268,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
list=list,
str=str,
tuple=tuple,
- _intstr=int.__str__,
+ _intstr=int.__repr__,
):
if _indent is not None and not isinstance(_indent, str):
@@ -307,7 +307,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
elif value is False:
yield buf + 'false'
elif isinstance(value, int):
- # Subclasses of int/float may override __str__, but we still
+ # Subclasses of int/float may override __repr__, but we still
# want to encode them as integers/floats in JSON. One example
# within the standard library is IntEnum.
yield buf + _intstr(value)
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 7355396..e093982 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -364,12 +364,10 @@ class LogRecord(object):
else:
self.process = None
- def __str__(self):
+ def __repr__(self):
return '<LogRecord: %s, %s, %s, %s, "%s">'%(self.name, self.levelno,
self.pathname, self.lineno, self.msg)
- __repr__ = __str__
-
def getMessage(self):
"""
Return the message for this LogRecord.
diff --git a/Lib/sre_constants.py b/Lib/sre_constants.py
index 13deb00..8e613cb 100644
--- a/Lib/sre_constants.py
+++ b/Lib/sre_constants.py
@@ -59,11 +59,9 @@ class _NamedIntConstant(int):
self.name = name
return self
- def __str__(self):
+ def __repr__(self):
return self.name
- __repr__ = __str__
-
MAXREPEAT = _NamedIntConstant(MAXREPEAT, 'MAXREPEAT')
def _makecodes(names):
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 0496b44..6cc9eb3 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -203,7 +203,6 @@ if _mswindows:
return "%s(%d)" % (self.__class__.__name__, int(self))
__del__ = Close
- __str__ = __repr__
else:
# When select or poll has indicated that the file is writable,
# we can write up to _PIPE_BUF bytes without risk of blocking.
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
index a0e923a..b987574 100644
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -186,8 +186,7 @@ INTERNAL_ERROR = -32603
class Error(Exception):
"""Base class for client errors."""
- def __str__(self):
- return repr(self)
+ __str__ = object.__str__
##
# Indicates an HTTP-level protocol error. This is raised by the HTTP
@@ -869,8 +868,6 @@ class MultiCall:
def __repr__(self):
return "<%s at %#x>" % (self.__class__.__name__, id(self))
- __str__ = __repr__
-
def __getattr__(self, name):
return _MultiCallMethod(self.__call_list, name)
@@ -1468,8 +1465,6 @@ class ServerProxy:
(self.__class__.__name__, self.__host, self.__handler)
)
- __str__ = __repr__
-
def __getattr__(self, name):
# magic method dispatcher
return _Method(self.__request, name)