Skip to content

Commit

Permalink
refactor: Replace super(.*self) with Python 3-specific super().
Browse files Browse the repository at this point in the history
We change all the instances except for the `test_helpers.py`
TimeTrackingCursor monkey-patching, which actually needs to specify
the base class.
  • Loading branch information
rht authored and timabbott committed Oct 30, 2017
1 parent d140451 commit c4fcff7
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 68 deletions.
6 changes: 3 additions & 3 deletions analytics/tests/test_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def test_process_dependent_stat(self):
class TestCountStats(AnalyticsTestCase):
def setUp(self):
# type: () -> None
super(TestCountStats, self).setUp()
super().setUp()
# This tests two things for each of the queries/CountStats: Handling
# more than 1 realm, and the time bounds (time_start and time_end in
# the queries).
Expand Down Expand Up @@ -812,7 +812,7 @@ def test_do_drop_single_stat(self):
class TestActiveUsersAudit(AnalyticsTestCase):
def setUp(self):
# type: () -> None
super(TestActiveUsersAudit, self).setUp()
super().setUp()
self.user = self.create_user()
self.stat = COUNT_STATS['active_users_audit:is_bot:day']
self.current_property = self.stat.property
Expand Down Expand Up @@ -975,7 +975,7 @@ def test_end_to_end_with_actions_dot_py(self):
class TestRealmActiveHumans(AnalyticsTestCase):
def setUp(self):
# type: () -> None
super(TestRealmActiveHumans, self).setUp()
super().setUp()
self.stat = COUNT_STATS['realm_active_humans::day']
self.current_property = self.stat.property

Expand Down
2 changes: 1 addition & 1 deletion confirmation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConfirmationKeyException(Exception):

def __init__(self, error_type):
# type: (int) -> None
super(ConfirmationKeyException, self).__init__()
super().__init__()
self.error_type = error_type

def render_confirmation_key_error(request, exception):
Expand Down
2 changes: 1 addition & 1 deletion docs/migration-renumbering.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ To fix them run './manage.py makemigrations --merge'
<output skipped>
File "/srv/zulip/zerver/lib/db.py", line 33, in execute
return wrapper_execute(self, super(TimeTrackingCursor, self).execute, query, vars)
return wrapper_execute(self, super().execute, query, vars)
File "/srv/zulip/zerver/lib/db.py", line 20, in wrapper_execute
return action(sql, params)
django.db.utils.ProgrammingError: relation "zerver_realmfilter" does not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HelpDocumentationSpider(BaseDocumentationSpider):
help_images_static_dir = get_help_images_dir(help_images_path)

def __init__(self, *args: Any, **kwargs: Any) -> None:
super(HelpDocumentationSpider, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.static_images = set() # type: Set

def _is_external_url(self, url: str) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BaseDocumentationSpider(scrapy.Spider):
attrs = ('href', 'src')

def __init__(self, *args: Any, **kwargs: Any) -> None:
super(BaseDocumentationSpider, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.has_error = False

def _set_error_state(self) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tools/run-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ class BaseWebsocketHandler(WebSocketHandler):

def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
super(BaseWebsocketHandler, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
# define client for target websocket server
self.client = None # type: Any

def get(self, *args, **kwargs):
# type: (*Any, **Any) -> Optional[Callable]
# use get method from WebsocketHandler
return super(BaseWebsocketHandler, self).get(*args, **kwargs)
return super().get(*args, **kwargs)

def open(self):
# type: () -> None
Expand Down Expand Up @@ -262,7 +262,7 @@ class CombineHandler(BaseWebsocketHandler):
def get(self, *args, **kwargs):
# type: (*Any, **Any) -> Optional[Callable]
if self.request.headers.get("Upgrade", "").lower() == 'websocket':
return super(CombineHandler, self).get(*args, **kwargs)
return super().get(*args, **kwargs)
return None

def head(self):
Expand Down Expand Up @@ -314,7 +314,7 @@ def prepare(self):
if 'X-REAL-IP' not in self.request.headers:
self.request.headers['X-REAL-IP'] = self.request.remote_ip
if self.request.headers.get("Upgrade", "").lower() == 'websocket':
return super(CombineHandler, self).prepare()
return super().prepare()
url = transform_url(
self.request.protocol,
self.request.path,
Expand Down Expand Up @@ -363,12 +363,12 @@ def __init__(self, enable_logging=False):
(r"/sockjs.*", TornadoHandler),
(r"/.*", DjangoHandler)
]
super(Application, self).__init__(handlers, enable_logging=enable_logging)
super().__init__(handlers, enable_logging=enable_logging)

def log_request(self, handler):
# type: (BaseWebsocketHandler) -> None
if self.settings['enable_logging']:
super(Application, self).log_request(handler)
super().log_request(handler)


def on_shutdown():
Expand Down
6 changes: 3 additions & 3 deletions zerver/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(self, *args, **kwargs):
self.realm_creation = kwargs['realm_creation']
del kwargs['realm_creation']

super(RegistrationForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if settings.TERMS_OF_SERVICE:
self.fields['terms'] = forms.BooleanField(required=True)
self.fields['realm_name'] = forms.CharField(
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
self.realm = kwargs.pop('realm', None)
self.from_multiuse_invite = kwargs.pop('from_multiuse_invite', False)
super(HomepageForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def clean_email(self):
# type: () -> str
Expand Down Expand Up @@ -331,7 +331,7 @@ def to_python(self, emails):
def validate(self, emails):
# type: (List[Text]) -> None
"""Check if value consists only of valid emails."""
super(MultiEmailField, self).validate(emails)
super().validate(emails)
for email in emails:
validate_email(email)

Expand Down
6 changes: 3 additions & 3 deletions zerver/lib/bugdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def __init__(self, parser):
# this class, so that bulleted lists (and only bulleted lists)
# work off 2-space indentation.
parser.markdown.tab_length = 2
super(UListProcessor, self).__init__(parser)
super().__init__(parser)
parser.markdown.tab_length = 4

class ListIndentProcessor(markdown.blockprocessors.ListIndentProcessor):
Expand All @@ -1050,7 +1050,7 @@ def __init__(self, parser):
# this class, so that bulleted lists (and only bulleted lists)
# work off 2-space indentation.
parser.markdown.tab_length = 2
super(ListIndentProcessor, self).__init__(parser)
super().__init__(parser)
parser.markdown.tab_length = 4

class BugdownUListPreprocessor(markdown.preprocessors.Preprocessor):
Expand Down Expand Up @@ -1260,7 +1260,7 @@ def __init__(self, *args, **kwargs):
"realm": [kwargs['realm'], "Realm name"]
}

super(Bugdown, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def extendMarkdown(self, md, md_globals):
# type: (markdown.Markdown, Dict[str, Any]) -> None
Expand Down
6 changes: 3 additions & 3 deletions zerver/lib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ class TimeTrackingCursor(cursor):

def execute(self, query, vars=None):
# type: (NonBinaryStr, Optional[ParamsT]) -> TimeTrackingCursor
return wrapper_execute(self, super(TimeTrackingCursor, self).execute, query, vars)
return wrapper_execute(self, super().execute, query, vars)

def executemany(self, query, vars):
# type: (NonBinaryStr, Iterable[Any]) -> TimeTrackingCursor
return wrapper_execute(self, super(TimeTrackingCursor, self).executemany, query, vars)
return wrapper_execute(self, super().executemany, query, vars)

class TimeTrackingConnection(connection):
"""A psycopg2 connection class that uses TimeTrackingCursors."""

def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
self.queries = [] # type: List[Dict[str, str]]
super(TimeTrackingConnection, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def cursor(self, *args, **kwargs):
# type: (*Any, **Any) -> TimeTrackingCursor
Expand Down
2 changes: 1 addition & 1 deletion zerver/lib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ def __str__(self):
class RateLimited(PermissionDenied):
def __init__(self, msg=""):
# type: (str) -> None
super(RateLimited, self).__init__(msg)
super().__init__(msg)
10 changes: 5 additions & 5 deletions zerver/lib/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BotIntegration(Integration):
def __init__(self, name, categories, logo=None, secondary_line_text=None,
display_name=None, doc=None):
# type: (str, List[str], Optional[str], Optional[str], Optional[str], Optional[str]) -> None
super(BotIntegration, self).__init__(
super().__init__(
name,
client_name=name,
categories=categories,
Expand Down Expand Up @@ -160,7 +160,7 @@ def __init__(self, name, categories, client_name=None, logo=None, secondary_line
# type: (str, List[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[bool]) -> None
if client_name is None:
client_name = self.DEFAULT_CLIENT_NAME.format(name=name.title())
super(WebhookIntegration, self).__init__(
super().__init__(
name,
client_name,
categories,
Expand Down Expand Up @@ -205,7 +205,7 @@ def __init__(self, name, categories, display_name=None, logo=None, logo_alt=None
if git_url is None:
git_url = self.GIT_URL_TEMPLATE.format(name)
self.git_url = git_url
super(HubotLozenge, self).__init__(
super().__init__(
name, name, categories,
logo=logo, display_name=display_name,
legacy=legacy
Expand All @@ -221,7 +221,7 @@ def __init__(self, name, categories, client_name=None, logo=None, secondary_line
# type: (str, List[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[bool]) -> None
url = self.DEFAULT_URL.format(name='github')

super(GithubIntegration, self).__init__(
super().__init__(
name,
categories,
client_name=client_name,
Expand Down Expand Up @@ -251,7 +251,7 @@ def __init__(self, name, *args, **kwargs):
# type: (str, *Any, **Any) -> None
assert kwargs.get("client_name") is None
client_name = self.DEFAULT_CLIENT_NAME.format(name=name.title())
super(EmbeddedBotIntegration, self).__init__(
super().__init__(
name, client_name, *args, **kwargs)

EMBEDDED_BOTS = [
Expand Down
4 changes: 2 additions & 2 deletions zerver/lib/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ExceptionFreeTornadoConnection(pika.adapters.TornadoConnection):
def _adapter_disconnect(self):
# type: () -> None
try:
super(ExceptionFreeTornadoConnection, self)._adapter_disconnect()
super()._adapter_disconnect()
except (pika.exceptions.ProbableAuthenticationError,
pika.exceptions.ProbableAccessDeniedError,
pika.exceptions.IncompatibleProtocolError) as e:
Expand All @@ -190,7 +190,7 @@ class TornadoQueueClient(SimpleQueueClient):
# https://pika.readthedocs.io/en/0.9.8/examples/asynchronous_consumer_example.html
def __init__(self):
# type: () -> None
super(TornadoQueueClient, self).__init__()
super().__init__()
# Enable rabbitmq heartbeat since TornadoConection can process them
self.rabbitmq_heartbeat = None
self._on_open_cbs = [] # type: List[Callable[[], None]]
Expand Down
12 changes: 6 additions & 6 deletions zerver/lib/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class TextTestResult(runner.TextTestResult):
"""
def __init__(self, *args, **kwargs):
# type: (*Any, **Any) -> None
super(TextTestResult, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.failed_tests = [] # type: List[str]

def addInfo(self, test, msg):
Expand Down Expand Up @@ -400,7 +400,7 @@ class ParallelTestSuite(django_runner.ParallelTestSuite):

def __init__(self, suite, processes, failfast):
# type: (TestSuite, int, bool) -> None
super(ParallelTestSuite, self).__init__(suite, processes, failfast)
super().__init__(suite, processes, failfast)
self.subsuites = SubSuiteList(self.subsuites) # type: SubSuiteList

class Runner(DiscoverRunner):
Expand Down Expand Up @@ -445,7 +445,7 @@ def setup_test_environment(self, *args, **kwargs):
settings.DATABASES['default']['NAME'] = settings.BACKEND_DATABASE_TEMPLATE
# We create/destroy the test databases in run_tests to avoid
# duplicate work when running in parallel mode.
return super(Runner, self).setup_test_environment(*args, **kwargs)
return super().setup_test_environment(*args, **kwargs)

def teardown_test_environment(self, *args, **kwargs):
# type: (*Any, **Any) -> Any
Expand All @@ -456,7 +456,7 @@ def teardown_test_environment(self, *args, **kwargs):
# destroy settings.BACKEND_DATABASE_TEMPLATE; we don't want that.
# So run this only in serial mode.
destroy_test_databases()
return super(Runner, self).teardown_test_environment(*args, **kwargs)
return super().teardown_test_environment(*args, **kwargs)

def run_tests(self, test_labels, extra_tests=None,
full_suite=False, **kwargs):
Expand Down Expand Up @@ -533,9 +533,9 @@ class SubSuiteList(list):
def __init__(self, suites):
# type: (List[TestSuite]) -> None
serialized_suites = [serialize_suite(s) for s in suites]
super(SubSuiteList, self).__init__(serialized_suites)
super().__init__(serialized_suites)

def __getitem__(self, index):
# type: (Any) -> Any
suite = super(SubSuiteList, self).__getitem__(index)
suite = super().__getitem__(index)
return deserialize_suite(suite)
2 changes: 1 addition & 1 deletion zerver/management/commands/compilemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def handle(self, *args: Any, **options: Any) -> None:
# version
settings.STATIC_ROOT = os.path.join(settings.DEPLOY_ROOT, "static")
settings.LOCALE_PATHS = (os.path.join(settings.DEPLOY_ROOT, 'static/locale'),)
super(Command, self).handle(*args, **options)
super().handle(*args, **options)
self.extract_language_options()
self.create_language_name_map()

Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Command(ZulipBaseCommand):

# Fix support for multi-line usage
def create_parser(self, *args: Any, **kwargs: Any) -> ArgumentParser:
parser = super(Command, self).create_parser(*args, **kwargs)
parser = super().create_parser(*args, **kwargs)
parser.formatter_class = RawTextHelpFormatter
return parser

Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/generate_realm_creation_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Command(BaseCommand):

# Fix support for multi-line usage
def create_parser(self, *args: Any, **kwargs: Any) -> ArgumentParser:
parser = super(Command, self).create_parser(*args, **kwargs)
parser = super().create_parser(*args, **kwargs)
parser.formatter_class = RawTextHelpFormatter
return parser

Expand Down
4 changes: 2 additions & 2 deletions zerver/management/commands/makemessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def strip_whitespaces(src: Text) -> Text:
class Command(makemessages.Command):

def add_arguments(self, parser: ArgumentParser) -> None:
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument('--frontend-source', type=str,
default='static/templates',
help='Name of the Handlebars template directory')
Expand Down Expand Up @@ -123,7 +123,7 @@ def my_templatize(src: Text, *args: Any, **kwargs: Any) -> Text:
ignore_patterns = options.get('ignore_patterns', [])
ignore_patterns.append('docs/*')
options['ignore_patterns'] = ignore_patterns
super(Command, self).handle(*args, **options)
super().handle(*args, **options)
finally:
template.endblock_re = old_endblock_re
template.block_re = old_block_re
Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/realm_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Command(ZulipBaseCommand):

# Fix support for multi-line usage
def create_parser(self, *args: Any, **kwargs: Any) -> CommandParser:
parser = super(Command, self).create_parser(*args, **kwargs)
parser = super().create_parser(*args, **kwargs)
parser.formatter_class = RawTextHelpFormatter
return parser

Expand Down
2 changes: 1 addition & 1 deletion zerver/management/commands/set_default_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Command(ZulipBaseCommand):

# Fix support for multi-line usage
def create_parser(self, *args: Any, **kwargs: Any) -> ArgumentParser:
parser = super(Command, self).create_parser(*args, **kwargs)
parser = super().create_parser(*args, **kwargs)
parser.formatter_class = RawTextHelpFormatter
return parser

Expand Down
4 changes: 2 additions & 2 deletions zerver/migrations/0077_add_file_name_field_to_realm_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def upload_emoji(self, realm_id: int, image_url: Text,

class LocalUploader(Uploader):
def __init__(self) -> None:
super(LocalUploader, self).__init__()
super().__init__()

@staticmethod
def mkdirs(path: Text) -> None:
Expand All @@ -108,7 +108,7 @@ def upload_files(self, response: Response, resized_image: binary_type,

class S3Uploader(Uploader):
def __init__(self) -> None:
super(S3Uploader, self).__init__()
super().__init__()
conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY)
bucket_name = settings.S3_AVATAR_BUCKET
self.bucket = conn.get_bucket(bucket_name, validate=False)
Expand Down
Loading

0 comments on commit c4fcff7

Please sign in to comment.