← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-repr-no-encode into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-repr-no-encode into launchpad:master.

Commit message:
Don't encode display names or titles in __repr__ on Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/395942

__repr__ is supposed to return a native string.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-repr-no-encode into launchpad:master.
diff --git a/lib/lp/blueprints/model/specificationworkitem.py b/lib/lp/blueprints/model/specificationworkitem.py
index 3f631b4..c3aa789 100644
--- a/lib/lp/blueprints/model/specificationworkitem.py
+++ b/lib/lp/blueprints/model/specificationworkitem.py
@@ -6,6 +6,7 @@ __all__ = [
     'SpecificationWorkItem',
     ]
 
+import six
 from storm.locals import (
     Bool,
     Int,
@@ -49,7 +50,8 @@ class SpecificationWorkItem(StormBase):
     deleted = Bool(allow_none=False, default=False)
 
     def __repr__(self):
-        title = self.title.encode('ASCII', 'backslashreplace')
+        title = six.ensure_str(
+            self.title, encoding='ASCII', errors='backslashreplace')
         assignee = getattr(self.assignee, 'name', None)
         return '<SpecificationWorkItem [%s] %s: %s of %s>' % (
             assignee, title, self.status.name, self.specification)
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index a3d4062..0db17cb 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -269,7 +269,8 @@ class Distribution(SQLBase, BugTargetBase, MakesAnnouncements,
     redirect_default_traversal = BoolCol(notNull=False, default=False)
 
     def __repr__(self):
-        display_name = self.display_name.encode('ASCII', 'backslashreplace')
+        display_name = six.ensure_str(
+            self.display_name, encoding='ASCII', errors='backslashreplace')
         return "<%s '%s' (%s)>" % (
             self.__class__.__name__, display_name, self.name)
 
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index a0beae5..ed09f67 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -547,7 +547,8 @@ class Person(
                      storm_validator=_validate_name)
 
     def __repr__(self):
-        displayname = self.displayname.encode('ASCII', 'backslashreplace')
+        displayname = six.ensure_str(
+            self.displayname, encoding='ASCII', errors='backslashreplace')
         return '<Person at 0x%x %s (%s)>' % (id(self), self.name, displayname)
 
     display_name = StringCol(dbName='displayname', notNull=True)