From 48826aa541f3a043690b90aa96f3fc07b7bc9fa9 Mon Sep 17 00:00:00 2001 From: Keda87 Date: Thu, 1 Dec 2016 08:08:51 -0500 Subject: [PATCH] Fixed #27546 -- Removed hardcoded class names in __repr__() methods. --- django/core/management/commands/makemessages.py | 5 ++++- django/core/serializers/base.py | 7 +++++-- django/db/migrations/state.py | 2 +- django/db/models/query.py | 4 ++-- django/db/models/sql/query.py | 2 +- django/utils/baseconv.py | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index 72390e4a75..527472e1c9 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -46,7 +46,10 @@ class TranslatableFile(object): self.locale_dir = locale_dir def __repr__(self): - return "" % os.sep.join([self.dirpath, self.file]) + return "<%s: %s>" % ( + self.__class__.__name__, + os.sep.join([self.dirpath, self.file]), + ) def __eq__(self, other): return self.path == other.path diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py index cc3d94e155..46fb25ea78 100644 --- a/django/core/serializers/base.py +++ b/django/core/serializers/base.py @@ -198,8 +198,11 @@ class DeserializedObject(object): self.m2m_data = m2m_data def __repr__(self): - return "" % ( - self.object._meta.label, self.object.pk) + return "<%s: %s(pk=%s)>" % ( + self.__class__.__name__, + self.object._meta.label, + self.object.pk, + ) def save(self, save_m2m=True, using=None, **kwargs): # Call save on the Model baseclass directly. This bypasses any diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index 1a9c23e618..489530abeb 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -588,7 +588,7 @@ class ModelState(object): raise ValueError("No index named %s on model %s" % (name, self.name)) def __repr__(self): - return "" % (self.app_label, self.name) + return "<%s: '%s.%s'>" % (self.__class__.__name__, self.app_label, self.name) def __eq__(self, other): return ( diff --git a/django/db/models/query.py b/django/db/models/query.py index 9497cb3ce6..f96a5f13ff 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -225,7 +225,7 @@ class QuerySet(object): data = list(self[:REPR_OUTPUT_SIZE + 1]) if len(data) > REPR_OUTPUT_SIZE: data[-1] = "...(remaining elements truncated)..." - return '' % data + return '<%s %r>' % (self.__class__.__name__, data) def __len__(self): self._fetch_all() @@ -1220,7 +1220,7 @@ class RawQuerySet(object): self.query.cursor.close() def __repr__(self): - return "" % self.query + return "<%s: %s>" % (self.__class__.__name__, self.query) def __getitem__(self, k): return list(self)[k] diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 97e90aa082..a1e476c592 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -86,7 +86,7 @@ class RawQuery(object): return iter(result) def __repr__(self): - return "" % self + return "<%s: %s>" % (self.__class__.__name__, self) @property def params_type(self): diff --git a/django/utils/baseconv.py b/django/utils/baseconv.py index f6c82a898a..158f0b0d92 100644 --- a/django/utils/baseconv.py +++ b/django/utils/baseconv.py @@ -55,7 +55,7 @@ class BaseConverter(object): raise ValueError('Sign character found in converter base digits.') def __repr__(self): - return "" % (len(self.digits), self.digits) + return "<%s: base%s (%s)>" % (self.__class__.__name__, len(self.digits), self.digits) def encode(self, i): neg, value = self.convert(i, self.decimal_digits, self.digits, '-')