zerver/lib: Remove inheritance from object.

This commit is contained in:
rht 2017-11-05 11:37:41 +01:00 committed by showell
parent 0e71b243ce
commit e311842a1b
22 changed files with 28 additions and 28 deletions

View File

@ -1241,7 +1241,7 @@ def do_send_messages(messages_maybe_none):
# intermingle sending zephyr messages with other messages. # intermingle sending zephyr messages with other messages.
return already_sent_ids + [message['message'].id for message in messages] return already_sent_ids + [message['message'].id for message in messages]
class UserMessageLite(object): class UserMessageLite:
''' '''
The Django ORM is too slow for bulk operations. This class The Django ORM is too slow for bulk operations. This class
is optimized for the simple use case of inserting a bunch of is optimized for the simple use case of inserting a bunch of

View File

@ -30,7 +30,7 @@ def get_user_profiles(emails, realm):
assert isinstance(e.messages[0], str) assert isinstance(e.messages[0], str)
raise JsonableError(e.messages[0]) raise JsonableError(e.messages[0])
class Addressee(object): class Addressee:
# This is really just a holder for vars that tended to be passed # This is really just a holder for vars that tended to be passed
# around in a non-type-safe way before this class was introduced. # around in a non-type-safe way before this class was introduced.
# #

View File

@ -37,7 +37,7 @@ def get_bot_handler(service_name):
class StateHandlerError(Exception): class StateHandlerError(Exception):
pass pass
class StateHandler(object): class StateHandler:
state_size_limit = 10000000 # type: int # TODO: Store this in the server configuration model. state_size_limit = 10000000 # type: int # TODO: Store this in the server configuration model.
def __init__(self, user_profile): def __init__(self, user_profile):
@ -76,7 +76,7 @@ class StateHandler(object):
# type: (Text) -> bool # type: (Text) -> bool
return is_key_in_bot_state(self.user_profile, key) return is_key_in_bot_state(self.user_profile, key)
class EmbeddedBotHandler(object): class EmbeddedBotHandler:
def __init__(self, user_profile): def __init__(self, user_profile):
# type: (UserProfile) -> None # type: (UserProfile) -> None
# Only expose a subset of our UserProfile's functionality # Only expose a subset of our UserProfile's functionality

View File

@ -1577,7 +1577,7 @@ def get_full_name_info(realm_id, full_names):
} }
return dct return dct
class MentionData(object): class MentionData:
def __init__(self, realm_id, content): def __init__(self, realm_id, content):
# type: (int, Text) -> None # type: (int, Text) -> None
full_names = possible_mentions(content) full_names = possible_mentions(content)

View File

@ -141,7 +141,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
output = [] # type: List[Text] output = [] # type: List[Text]
class BaseHandler(object): class BaseHandler:
def handle_line(self, line): def handle_line(self, line):
# type: (Text) -> None # type: (Text) -> None
raise NotImplementedError() raise NotImplementedError()

View File

@ -180,7 +180,7 @@ def floatify_datetime_fields(data, table):
utc_naive = dt.replace(tzinfo=None) - dt.utcoffset() utc_naive = dt.replace(tzinfo=None) - dt.utcoffset()
item[field] = (utc_naive - datetime.datetime(1970, 1, 1)).total_seconds() item[field] = (utc_naive - datetime.datetime(1970, 1, 1)).total_seconds()
class Config(object): class Config:
''' '''
A Config object configures a single table for exporting (and, A Config object configures a single table for exporting (and,
maybe some day importing as well. maybe some day importing as well.

View File

@ -50,7 +50,7 @@ CATEGORIES = {
'bots': _('Interactive bots'), 'bots': _('Interactive bots'),
} # type: Dict[str, str] } # type: Dict[str, str]
class Integration(object): class Integration:
DEFAULT_LOGO_STATIC_PATH_PNG = 'static/images/integrations/logos/{name}.png' DEFAULT_LOGO_STATIC_PATH_PNG = 'static/images/integrations/logos/{name}.png'
DEFAULT_LOGO_STATIC_PATH_SVG = 'static/images/integrations/logos/{name}.svg' DEFAULT_LOGO_STATIC_PATH_SVG = 'static/images/integrations/logos/{name}.svg'

View File

@ -15,7 +15,7 @@ from logging import Logger
# Adapted http://djangosnippets.org/snippets/2242/ by user s29 (October 25, 2010) # Adapted http://djangosnippets.org/snippets/2242/ by user s29 (October 25, 2010)
class _RateLimitFilter(object): class _RateLimitFilter:
last_error = datetime.min.replace(tzinfo=timezone_utc) last_error = datetime.min.replace(tzinfo=timezone_utc)
def filter(self, record): def filter(self, record):

View File

@ -82,7 +82,7 @@ def message_to_dict_json(message):
# type: (Message) -> binary_type # type: (Message) -> binary_type
return MessageDict.to_dict_uncached(message) return MessageDict.to_dict_uncached(message)
class MessageDict(object): class MessageDict:
@staticmethod @staticmethod
def wide_dict(message): def wide_dict(message):
# type: (Message) -> Dict[str, Any] # type: (Message) -> Dict[str, Any]
@ -413,7 +413,7 @@ class MessageDict(object):
client_gravatar=client_gravatar, client_gravatar=client_gravatar,
) )
class ReactionDict(object): class ReactionDict:
@staticmethod @staticmethod
def build_dict_from_raw_db_row(row): def build_dict_from_raw_db_row(row):
# type: (Dict[str, Any]) -> Dict[str, Any] # type: (Dict[str, Any]) -> Dict[str, Any]

View File

@ -19,7 +19,7 @@ from zerver.lib.queue import retry_event
from zerver.lib.validator import check_dict, check_string from zerver.lib.validator import check_dict, check_string
from zerver.decorator import JsonableError from zerver.decorator import JsonableError
class OutgoingWebhookServiceInterface(object): class OutgoingWebhookServiceInterface:
def __init__(self, base_url, token, user_profile, service_name): def __init__(self, base_url, token, user_profile, service_name):
# type: (Text, Text, UserProfile, Text) -> None # type: (Text, Text, UserProfile, Text) -> None

View File

@ -20,7 +20,7 @@ Consumer = Callable[[BlockingChannel, Basic.Deliver, pika.BasicProperties, str],
# rabbitmq/pika's queuing system; its purpose is to just provide an # rabbitmq/pika's queuing system; its purpose is to just provide an
# interface for external files to put things into queues and take them # interface for external files to put things into queues and take them
# out from bots without having to import pika code all over our codebase. # out from bots without having to import pika code all over our codebase.
class SimpleQueueClient(object): class SimpleQueueClient:
def __init__(self): def __init__(self):
# type: () -> None # type: () -> None
self.log = logging.getLogger('zulip.queue') self.log = logging.getLogger('zulip.queue')

View File

@ -21,7 +21,7 @@ rules = settings.RATE_LIMITING_RULES # type: List[Tuple[int, int]]
KEY_PREFIX = '' KEY_PREFIX = ''
class RateLimitedObject(object): class RateLimitedObject:
def get_keys(self): def get_keys(self):
# type: () -> List[Text] # type: () -> List[Text]
key_fragment = self.key_fragment() key_fragment = self.key_fragment()

View File

@ -43,11 +43,11 @@ class RequestVariableConversionError(JsonableError):
return _("Bad value for '{var_name}': {bad_value}") return _("Bad value for '{var_name}': {bad_value}")
# Used in conjunction with @has_request_variables, below # Used in conjunction with @has_request_variables, below
class REQ(object): class REQ:
# NotSpecified is a sentinel value for determining whether a # NotSpecified is a sentinel value for determining whether a
# default value was specified for a request variable. We can't # default value was specified for a request variable. We can't
# use None because that could be a valid, user-specified default # use None because that could be a valid, user-specified default
class _NotSpecified(object): class _NotSpecified:
pass pass
NotSpecified = _NotSpecified() NotSpecified = _NotSpecified()

View File

@ -19,7 +19,7 @@ from zerver.lib.logging_util import create_logger
logger = create_logger('zulip.send_email', settings.EMAIL_LOG_PATH, 'INFO') logger = create_logger('zulip.send_email', settings.EMAIL_LOG_PATH, 'INFO')
class FromAddress(object): class FromAddress:
SUPPORT = parseaddr(settings.ZULIP_ADMINISTRATOR)[1] SUPPORT = parseaddr(settings.ZULIP_ADMINISTRATOR)[1]
NOREPLY = parseaddr(settings.NOREPLY_EMAIL_ADDRESS)[1] NOREPLY = parseaddr(settings.NOREPLY_EMAIL_ADDRESS)[1]

View File

@ -71,7 +71,7 @@ def dict_with_str_keys(dct, encoding='utf-8'):
"""applies force_str on the keys of a dict (non-recursively)""" """applies force_str on the keys of a dict (non-recursively)"""
return {force_str(key, encoding): value for key, value in dct.items()} return {force_str(key, encoding): value for key, value in dct.items()}
class ModelReprMixin(object): class ModelReprMixin:
""" """
This mixin provides a python 2 and 3 compatible way of handling string representation of a model. This mixin provides a python 2 and 3 compatible way of handling string representation of a model.
When declaring a model, inherit this mixin before django.db.models.Model. When declaring a model, inherit this mixin before django.db.models.Model.

View File

@ -4,7 +4,7 @@ from typing import (Dict, List)
from django.db import connection from django.db import connection
from zerver.models import Recipient from zerver.models import Recipient
class StreamRecipientMap(object): class StreamRecipientMap:
''' '''
This class maps stream_id -> recipient_id and vice versa. This class maps stream_id -> recipient_id and vice versa.
It is useful for bulk operations. Call the populate_* methods It is useful for bulk operations. Call the populate_* methods

View File

@ -9,7 +9,7 @@ from zerver.models import (
MutedTopic, MutedTopic,
) )
class StreamTopicTarget(object): class StreamTopicTarget:
''' '''
This class is designed to help us move to a This class is designed to help us move to a
StreamTopic table or something similar. It isolates StreamTopic table or something similar. It isolates

View File

@ -257,12 +257,12 @@ def get_user_messages(user_profile):
order_by('message') order_by('message')
return [um.message for um in query] return [um.message for um in query]
class DummyHandler(object): class DummyHandler:
def __init__(self): def __init__(self):
# type: () -> None # type: () -> None
allocate_handler_id(self) # type: ignore # this is a testing mock allocate_handler_id(self) # type: ignore # this is a testing mock
class POSTRequestMock(object): class POSTRequestMock:
method = "POST" method = "POST"
def __init__(self, post_data, user_profile): def __init__(self, post_data, user_profile):
@ -275,7 +275,7 @@ class POSTRequestMock(object):
self.META = {'PATH_INFO': 'test'} self.META = {'PATH_INFO': 'test'}
self.path = '' self.path = ''
class HostRequestMock(object): class HostRequestMock:
"""A mock request object where get_host() works. Useful for testing """A mock request object where get_host() works. Useful for testing
routes that use Zulip's subdomains feature""" routes that use Zulip's subdomains feature"""
@ -296,7 +296,7 @@ class HostRequestMock(object):
# type: () -> Text # type: () -> Text
return self.host return self.host
class MockPythonResponse(object): class MockPythonResponse:
def __init__(self, text, status_code): def __init__(self, text, status_code):
# type: (Text, int) -> None # type: (Text, int) -> None
self.text = text self.text = text

View File

@ -7,7 +7,7 @@ from six.moves import map
from typing import Dict, List, Text from typing import Dict, List, Text
class SourceMap(object): class SourceMap:
'''Map (line, column) pairs from generated to source file.''' '''Map (line, column) pairs from generated to source file.'''
def __init__(self, sourcemap_dirs): def __init__(self, sourcemap_dirs):

View File

@ -124,7 +124,7 @@ def resize_emoji(image_data, size=DEFAULT_EMOJI_SIZE):
### Common ### Common
class ZulipUploadBackend(object): class ZulipUploadBackend:
def upload_message_image(self, uploaded_file_name, uploaded_file_size, def upload_message_image(self, uploaded_file_name, uploaded_file_size,
content_type, file_data, user_profile, target_realm=None): content_type, file_data, user_profile, target_realm=None):
# type: (Text, int, Optional[Text], binary_type, UserProfile, Optional[Realm]) -> Text # type: (Text, int, Optional[Text], binary_type, UserProfile, Optional[Realm]) -> Text

View File

@ -2,7 +2,7 @@ from typing import Any, Text
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
class BaseParser(object): class BaseParser:
def __init__(self, html_source): def __init__(self, html_source):
# type: (Text) -> None # type: (Text) -> None
self._soup = BeautifulSoup(html_source, "lxml") self._soup = BeautifulSoup(html_source, "lxml")

View File

@ -30,7 +30,7 @@ def statsd_key(val, clean_periods=False):
return val return val
class StatsDWrapper(object): class StatsDWrapper:
"""Transparently either submit metrics to statsd """Transparently either submit metrics to statsd
or do nothing without erroring out""" or do nothing without erroring out"""