diff --git a/analytics/lib/counts.py b/analytics/lib/counts.py index 72a8f88a19..6d5cc2b97e 100644 --- a/analytics/lib/counts.py +++ b/analytics/lib/counts.py @@ -46,9 +46,9 @@ class CountStat(object): else: # frequency == CountStat.DAY self.interval = timedelta(days=1) - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.property,) + return "" % (self.property,) class LoggingCountStat(CountStat): def __init__(self, property, output_table, frequency): diff --git a/analytics/models.py b/analytics/models.py index 0a679d869a..82fdadcf4f 100644 --- a/analytics/models.py +++ b/analytics/models.py @@ -18,9 +18,9 @@ class FillState(models.Model): last_modified = models.DateTimeField(auto_now=True) # type: datetime.datetime - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.property, self.end_time, self.state) + return "" % (self.property, self.end_time, self.state) # The earliest/starting end_time in FillState # We assume there is at least one realm @@ -42,9 +42,9 @@ def last_successful_fill(property): class Anomaly(models.Model): info = models.CharField(max_length=1000) # type: Text - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.info, self.id) + return "" % (self.info, self.id) class BaseCount(models.Model): # Note: When inheriting from BaseCount, you may want to rearrange @@ -64,9 +64,9 @@ class InstallationCount(BaseCount): class Meta(object): unique_together = ("property", "subgroup", "end_time") - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.property, self.subgroup, self.value) + return "" % (self.property, self.subgroup, self.value) class RealmCount(BaseCount): realm = models.ForeignKey(Realm) @@ -75,9 +75,9 @@ class RealmCount(BaseCount): unique_together = ("realm", "property", "subgroup", "end_time") index_together = ["property", "end_time"] - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.realm, self.property, self.subgroup, self.value) + return "" % (self.realm, self.property, self.subgroup, self.value) class UserCount(BaseCount): user = models.ForeignKey(UserProfile) @@ -89,9 +89,9 @@ class UserCount(BaseCount): # aggregating from users to realms index_together = ["property", "realm", "end_time"] - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.user, self.property, self.subgroup, self.value) + return "" % (self.user, self.property, self.subgroup, self.value) class StreamCount(BaseCount): stream = models.ForeignKey(Stream) @@ -103,6 +103,6 @@ class StreamCount(BaseCount): # aggregating from streams to realms index_together = ["property", "realm", "end_time"] - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.stream, self.property, self.subgroup, self.value, self.id) + return "" % (self.stream, self.property, self.subgroup, self.value, self.id) diff --git a/confirmation/models.py b/confirmation/models.py index 21782bcb4f..9080aa0b41 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -98,7 +98,7 @@ class Confirmation(models.Model): MULTIUSE_INVITE = 6 type = models.PositiveSmallIntegerField() # type: int - def __unicode__(self): + def __str__(self): # type: () -> Text return '' % (self.content_object,) diff --git a/tools/coveragerc b/tools/coveragerc index 7754ab583d..2b1c55e964 100644 --- a/tools/coveragerc +++ b/tools/coveragerc @@ -9,8 +9,8 @@ exclude_lines = raise NotImplementedError() # Don't require coverage for test suite AssertionError -- they're usually for clarity raise AssertionError - # Don't require coverage for __unicode__ statements just used for printing - def __unicode__[(]self[)]: + # Don't require coverage for __str__ statements just used for printing + def __str__[(]self[)]: [run] omit = diff --git a/zerver/models.py b/zerver/models.py index 09f1fbfdae..8e86529238 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -222,9 +222,9 @@ class Realm(models.Model): ret[k] = v return ret - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.string_id, self.id) + return "" % (self.string_id, self.id) @cache_with_key(get_realm_emoji_cache_key, timeout=3600*24*7) def get_emoji(self): @@ -383,9 +383,9 @@ class RealmEmoji(models.Model): class Meta(object): unique_together = ("realm", "name") - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.realm.string_id, self.name, self.file_name) + return "" % (self.realm.string_id, self.name, self.file_name) def get_realm_emoji_uncached(realm): # type: (Realm) -> Dict[Text, Dict[str, Any]] @@ -442,9 +442,9 @@ class RealmFilter(models.Model): class Meta(object): unique_together = ("realm", "pattern") - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.realm.string_id, self.pattern, self.url_format_string) + return "" % (self.realm.string_id, self.pattern, self.url_format_string) def get_realm_filters_cache_key(realm_id): # type: (int) -> Text @@ -703,9 +703,9 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): else: return False - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.email, self.realm) + return "" % (self.email, self.realm) @property def is_incoming_webhook(self): @@ -890,9 +890,9 @@ class Stream(models.Model): date_created = models.DateTimeField(default=timezone_now) # type: datetime.datetime deactivated = models.BooleanField(default=False) # type: bool - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.name,) + return "" % (self.name,) def is_public(self): # type: () -> bool @@ -942,10 +942,10 @@ class Recipient(models.Model): # Raises KeyError if invalid return self._type_names[self.type] - def __unicode__(self): + def __str__(self): # type: () -> Text display_recipient = get_display_recipient(self) - return u"" % (display_recipient, self.type_id, self.type) + return "" % (display_recipient, self.type_id, self.type) class MutedTopic(models.Model): user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE) @@ -956,16 +956,16 @@ class MutedTopic(models.Model): class Meta(object): unique_together = ('user_profile', 'stream', 'topic_name') - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.user_profile.email, self.stream.name, self.topic_name) + return "" % (self.user_profile.email, self.stream.name, self.topic_name) class Client(models.Model): name = models.CharField(max_length=30, db_index=True, unique=True) # type: Text - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"" % (self.name,) + return "" % (self.name,) get_client_cache = {} # type: Dict[Text, Client] def get_client(name): @@ -1123,11 +1123,11 @@ class AbstractMessage(models.Model): class Meta(object): abstract = True - def __unicode__(self): + def __str__(self): # type: () -> Text display_recipient = get_display_recipient(self.recipient) - return u"<%s: %s / %s / %r>" % (self.__class__.__name__, display_recipient, - self.subject, self.sender) + return "<%s: %s / %s / %r>" % (self.__class__.__name__, display_recipient, + self.subject, self.sender) class ArchivedMessage(AbstractMessage): @@ -1330,11 +1330,11 @@ class AbstractUserMessage(models.Model): if flags & (2 ** i) ] - def __unicode__(self): + def __str__(self): # type: () -> Text display_recipient = get_display_recipient(self.message.recipient) - return u"<%s: %s / %s (%s)>" % (self.__class__.__name__, display_recipient, - self.user_profile.email, self.flags_list()) + return "<%s: %s / %s (%s)>" % (self.__class__.__name__, display_recipient, + self.user_profile.email, self.flags_list()) class ArchivedUserMessage(AbstractUserMessage): @@ -1373,9 +1373,9 @@ class AbstractAttachment(models.Model): class Meta(object): abstract = True - def __unicode__(self): + def __str__(self): # type: () -> Text - return u"<%s: %s>" % (self.__class__.__name__, self.file_name,) + return "<%s: %s>" % (self.__class__.__name__, self.file_name,) class ArchivedAttachment(AbstractAttachment): @@ -1455,9 +1455,9 @@ class Subscription(models.Model): class Meta(object): unique_together = ("user_profile", "recipient") - def __unicode__(self): + def __str__(self): # type: () -> Text - return u" %s>" % (self.user_profile, self.recipient) + return " %s>" % (self.user_profile, self.recipient) @cache_with_key(user_profile_by_id_cache_key, timeout=3600*24*7) def get_user_profile_by_id(uid): @@ -1839,8 +1839,8 @@ class ScheduledEmail(AbstractScheduledJob): def __str__(self): # type: () -> Text - return u"" % (self.type, self.user or self.address, - self.scheduled_timestamp) + return "" % (self.type, self.user or self.address, + self.scheduled_timestamp) EMAIL_TYPES = { 'followup_day1': ScheduledEmail.WELCOME, @@ -1862,12 +1862,12 @@ class RealmAuditLog(models.Model): backfilled = models.BooleanField(default=False) # type: bool extra_data = models.TextField(null=True) # type: Optional[Text] - def __unicode__(self): + def __str__(self): # type: () -> str if self.modified_user is not None: - return u"" % (self.modified_user, self.event_type, self.event_time) + return "" % (self.modified_user, self.event_type, self.event_time) if self.modified_stream is not None: - return u"" % (self.modified_stream, self.event_type, self.event_time) + return "" % (self.modified_stream, self.event_type, self.event_time) return "" % (self.realm, self.event_type, self.event_time) class UserHotspot(models.Model): diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py index 4f878b9972..d0784ed3e0 100644 --- a/zerver/tests/test_bugdown.py +++ b/zerver/tests/test_bugdown.py @@ -623,7 +623,7 @@ class BugdownTest(ZulipTestCase): url_format_string=url_format_string) realm_filter.save() self.assertEqual( - realm_filter.__unicode__(), + realm_filter.__str__(), '[0-9]{2,8})' ' https://trac.zulip.net/ticket/%(id)s>') diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index 4def2cf9d8..adda4dc8d0 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -328,12 +328,12 @@ class PersonalMessagesTest(ZulipTestCase): with mock.patch('zerver.models.get_display_recipient', return_value='recip'): self.assertEqual(str(message), - u'>>') user_message = most_recent_usermessage(user_profile) self.assertEqual(str(user_message), - u'' + '' ) @slow("checks several profiles") diff --git a/zerver/tests/test_presence.py b/zerver/tests/test_presence.py index 52a6d583fd..ee8a54c21a 100644 --- a/zerver/tests/test_presence.py +++ b/zerver/tests/test_presence.py @@ -53,10 +53,10 @@ class TestClientModel(ZulipTestCase): def test_client_stringification(self): # type: () -> None ''' - This test is designed to cover __unicode__ method for Client. + This test is designed to cover __str__ method for Client. ''' client = make_client('some_client') - self.assertEqual(str(client), u'') + self.assertEqual(str(client), '') class UserPresenceModelTests(ZulipTestCase): def test_date_logic(self): diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 293798dffb..d065bf68d1 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -2146,7 +2146,7 @@ class SubscriptionAPITest(ZulipTestCase): self.assert_adding_subscriptions_for_principal(invitee_email, invitee_realm, invite_streams) subscription = self.get_subscription(user_profile, invite_streams[0]) - with mock.patch('zerver.models.Recipient.__unicode__', return_value='recip'): + with mock.patch('zerver.models.Recipient.__str__', return_value='recip'): self.assertEqual(str(subscription), u'> -> recip>' % (self.example_email('iago'),))