lint: Wrap many very long lines in the Python codebase.

This decreases the maximum line length in our Python codebase to 130.
This commit is contained in:
Tim Abbott 2017-10-26 17:31:10 -07:00
parent c771873439
commit be619fe881
10 changed files with 79 additions and 39 deletions

View File

@ -119,8 +119,10 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--development', action='store_true', dest='development', help='For setting up the developer env for zulip')
group.add_argument('--production', action='store_false', dest='development', help='For setting up the production env for zulip')
group.add_argument('--development', action='store_true', dest='development',
help='For setting up the developer env for zulip')
group.add_argument('--production', action='store_false', dest='development',
help='For setting up the production env for zulip')
results = parser.parse_args()
generate_secrets(results.development)

View File

@ -586,7 +586,7 @@ def build_custom_checkers(by_lang):
for fn in by_lang['py']:
if 'custom_check.py' in fn:
continue
if custom_check_file(fn, 'py', python_rules, color, max_length=140):
if custom_check_file(fn, 'py', python_rules, color, max_length=130):
failed = True
return failed

View File

@ -62,7 +62,8 @@ RespondAsynchronously = _RespondAsynchronously()
def asynchronous(method):
# type: (Callable[..., Union[HttpResponse, _RespondAsynchronously]]) -> Callable[..., Union[HttpResponse, _RespondAsynchronously]]
# TODO: this should be the correct annotation when mypy gets fixed: type:
# (Callable[[HttpRequest, base.BaseHandler, Sequence[Any], Dict[str, Any]], Union[HttpResponse, _RespondAsynchronously]]) ->
# (Callable[[HttpRequest, base.BaseHandler, Sequence[Any], Dict[str, Any]],
# Union[HttpResponse, _RespondAsynchronously]]) ->
# Callable[[HttpRequest, Sequence[Any], Dict[str, Any]], Union[HttpResponse, _RespondAsynchronously]]
# TODO: see https://github.com/python/mypy/issues/1655
@wraps(method)

View File

@ -1308,8 +1308,11 @@ class Bugdown(markdown.Extension):
md.inlinePatterns.add('avatar', Avatar(AVATAR_REGEX), '>backtick')
md.inlinePatterns.add('gravatar', Avatar(GRAVATAR_REGEX), '>backtick')
md.inlinePatterns.add('stream_subscribe_button',
StreamSubscribeButton(r'!_stream_subscribe_button\((?P<stream_name>(?:[^)\\]|\\\)|\\)*)\)'), '>backtick')
md.inlinePatterns.add(
'stream_subscribe_button',
StreamSubscribeButton(
r'!_stream_subscribe_button\((?P<stream_name>(?:[^)\\]|\\\)|\\)*)\)'),
'>backtick')
md.inlinePatterns.add(
'modal_link',
ModalLink(r'!modal_link\((?P<relative_url>[^)]*), (?P<text>[^)]*)\)'),

View File

@ -1187,7 +1187,8 @@ def export_messages_single_user(user_profile, output_dir, chunk_size=1000):
min_id = -1
dump_file_id = 1
while True:
actual_query = user_message_query.select_related("message", "message__sending_client").filter(id__gt=min_id)[0:chunk_size]
actual_query = user_message_query.select_related(
"message", "message__sending_client").filter(id__gt=min_id)[0:chunk_size]
user_message_chunk = [um for um in actual_query]
user_message_ids = set(um.id for um in user_message_chunk)

View File

@ -527,7 +527,9 @@ def handle_push_notification(user_profile_id, missed_message):
def failure_processor(event):
# type: (Dict[str, Any]) -> None
logging.warning("Maximum retries exceeded for trigger:%s event:push_notification" % (event['user_profile_id']))
logging.warning(
"Maximum retries exceeded for trigger:%s event:push_notification" % (
event['user_profile_id']))
retry_event('missedmessage_mobile_notifications', missed_message,
failure_processor)
@ -547,4 +549,5 @@ def handle_push_notification(user_profile_id, missed_message):
send_android_push_notification(android_devices, gcm_payload)
except UserMessage.DoesNotExist:
logging.error("Could not find UserMessage with message_id %s" % (missed_message['message_id'],))
logging.error("Could not find UserMessage with message_id %s" % (
missed_message['message_id'],))

View File

@ -279,7 +279,8 @@ def api_github_landing(request, user_profile, event=REQ(),
forged=False, subject_name=subject,
message_content=content)
def build_message_from_gitlog(user_profile, name, ref, commits, before, after, url, pusher, forced=None, created=None, deleted=False):
def build_message_from_gitlog(user_profile, name, ref, commits, before, after,
url, pusher, forced=None, created=None, deleted=False):
# type: (UserProfile, Text, Text, List[Dict[str, str]], Text, Text, Text, Text, Optional[Text], Optional[Text], Optional[bool]) -> Tuple[Text, Text]
short_ref = re.sub(r'^refs/heads/', '', ref)
subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)

View File

@ -166,7 +166,8 @@ def api_stripe_webhook(request, user_profile,
def amount(amount, currency):
# type: (int, str) -> str
# zero-decimal currencies
zero_decimal_currencies = ["bif", "djf", "jpy", "krw", "pyg", "vnd", "xaf", "xpf", "clp", "gnf", "kmf", "mga", "rwf", "vuv", "xof"]
zero_decimal_currencies = ["bif", "djf", "jpy", "krw", "pyg", "vnd", "xaf",
"xpf", "clp", "gnf", "kmf", "mga", "rwf", "vuv", "xof"]
if currency in zero_decimal_currencies:
return str(amount) + currency
else:

View File

@ -66,7 +66,8 @@ templates = {
},
'relateduserstory': {
'create': u':package: %(user)s added a related user story **%(userstory_subject)s** to the epic **%(epic_subject)s**',
'delete': u':cross_mark: %(user)s removed a related user story **%(userstory_subject)s** from the epic **%(epic_subject)s**',
'delete': (u':cross_mark: %(user)s removed a related user story ' +
u'**%(userstory_subject)s** from the epic **%(epic_subject)s**'),
},
'userstory': {
'create': u':package: %(user)s created user story **%(subject)s**.',

View File

@ -63,7 +63,8 @@ v1_api_and_json_patterns = [
{'PATCH': 'zerver.views.realm.update_realm'}),
# Returns a 204, used by desktop app to verify connectivity status
url(r'generate_204$', zerver.views.registration.generate_204, name='zerver.views.registration.generate_204'),
url(r'generate_204$', zerver.views.registration.generate_204,
name='zerver.views.registration.generate_204'),
# realm/domains -> zerver.views.realm_domains
url(r'^realm/domains$', rest_dispatch,
@ -307,24 +308,32 @@ i18n_urls = [
# We have a desktop-specific landing page in case we change our /
# to not log in in the future. We don't want to require a new
# desktop app build for everyone in that case
url(r'^desktop_home/$', zerver.views.home.desktop_home, name='zerver.views.home.desktop_home'),
url(r'^desktop_home/$', zerver.views.home.desktop_home,
name='zerver.views.home.desktop_home'),
url(r'^accounts/login/sso/$', zerver.views.auth.remote_user_sso, name='login-sso'),
url(r'^accounts/login/jwt/$', zerver.views.auth.remote_user_jwt, name='login-jwt'),
url(r'^accounts/login/social/(\w+)$', zerver.views.auth.start_social_login, name='login-social'),
url(r'^accounts/login/google/$', zerver.views.auth.start_google_oauth2, name='zerver.views.auth.start_google_oauth2'),
url(r'^accounts/login/social/(\w+)$', zerver.views.auth.start_social_login,
name='login-social'),
url(r'^accounts/login/google/$', zerver.views.auth.start_google_oauth2,
name='zerver.views.auth.start_google_oauth2'),
url(r'^accounts/login/google/send/$',
zerver.views.auth.send_oauth_request_to_google,
name='zerver.views.auth.send_oauth_request_to_google'),
url(r'^accounts/login/google/done/$', zerver.views.auth.finish_google_oauth2, name='zerver.views.auth.finish_google_oauth2'),
url(r'^accounts/login/subdomain/$', zerver.views.auth.log_into_subdomain, name='zerver.views.auth.log_into_subdomain'),
url(r'^accounts/login/local/$', zerver.views.auth.dev_direct_login, name='zerver.views.auth.dev_direct_login'),
url(r'^accounts/login/google/done/$', zerver.views.auth.finish_google_oauth2,
name='zerver.views.auth.finish_google_oauth2'),
url(r'^accounts/login/subdomain/$', zerver.views.auth.log_into_subdomain,
name='zerver.views.auth.log_into_subdomain'),
url(r'^accounts/login/local/$', zerver.views.auth.dev_direct_login,
name='zerver.views.auth.dev_direct_login'),
# We have two entries for accounts/login to allow reverses on the Django
# view we're wrapping to continue to function.
url(r'^accounts/login/', zerver.views.auth.login_page, {'template_name': 'zerver/login.html'}, name='zerver.views.auth.login_page'),
url(r'^accounts/login/', zerver.views.auth.login_page,
{'template_name': 'zerver/login.html'}, name='zerver.views.auth.login_page'),
url(r'^accounts/login/', login, {'template_name': 'zerver/login.html'},
name='django.contrib.auth.views.login'),
url(r'^accounts/logout/', zerver.views.auth.logout_then_login, name='zerver.views.auth.logout_then_login'),
url(r'^accounts/logout/', zerver.views.auth.logout_then_login,
name='zerver.views.auth.logout_then_login'),
url(r'^accounts/webathena_kerberos_login/',
zerver.views.zephyr.webathena_kerberos_login,
@ -350,8 +359,10 @@ i18n_urls = [
name='zerver.views.registration.show_deactivation_notice'),
# Avatar
url(r'^avatar/(?P<email_or_id>[\S]+)?/(?P<medium>[\S]+)?', zerver.views.users.avatar, name='zerver.views.users.avatar'),
url(r'^avatar/(?P<email_or_id>[\S]+)?', zerver.views.users.avatar, name='zerver.views.users.avatar'),
url(r'^avatar/(?P<email_or_id>[\S]+)?/(?P<medium>[\S]+)?', zerver.views.users.avatar,
name='zerver.views.users.avatar'),
url(r'^avatar/(?P<email_or_id>[\S]+)?', zerver.views.users.avatar,
name='zerver.views.users.avatar'),
# Registration views, require a confirmation ID.
url(r'^accounts/register/social/(\w+)$',
@ -360,10 +371,12 @@ i18n_urls = [
url(r'^accounts/home/', zerver.views.registration.accounts_home,
name='zerver.views.registration.accounts_home'),
url(r'^accounts/send_confirm/(?P<email>[\S]+)?',
TemplateView.as_view(template_name='zerver/accounts_send_confirm.html'), name='send_confirm'),
TemplateView.as_view(template_name='zerver/accounts_send_confirm.html'),
name='send_confirm'),
url(r'^accounts/register/', zerver.views.registration.accounts_register,
name='zerver.views.registration.accounts_register'),
url(r'^accounts/do_confirm/(?P<confirmation_key>[\w]+)', confirmation.views.confirm, name='confirmation.views.confirm'),
url(r'^accounts/do_confirm/(?P<confirmation_key>[\w]+)',
confirmation.views.confirm, name='confirmation.views.confirm'),
url(r'^accounts/confirm_new_email/(?P<confirmation_key>[\w]+)',
zerver.views.user_settings.confirm_email_change,
@ -372,29 +385,38 @@ i18n_urls = [
# Email unsubscription endpoint. Allows for unsubscribing from various types of emails,
# including the welcome emails (day 1 & 2), missed PMs, etc.
url(r'^accounts/unsubscribe/(?P<email_type>[\w]+)/(?P<confirmation_key>[\w]+)',
zerver.views.unsubscribe.email_unsubscribe, name='zerver.views.unsubscribe.email_unsubscribe'),
zerver.views.unsubscribe.email_unsubscribe,
name='zerver.views.unsubscribe.email_unsubscribe'),
# Portico-styled page used to provide email confirmation of terms acceptance.
url(r'^accounts/accept_terms/$', zerver.views.home.accounts_accept_terms, name='zerver.views.home.accounts_accept_terms'),
url(r'^accounts/accept_terms/$', zerver.views.home.accounts_accept_terms,
name='zerver.views.home.accounts_accept_terms'),
# Find your account
url(r'^accounts/find/$', zerver.views.registration.find_account, name='zerver.views.registration.find_account'),
url(r'^accounts/find/$', zerver.views.registration.find_account,
name='zerver.views.registration.find_account'),
# Realm Creation
url(r'^create_realm/$', zerver.views.registration.create_realm, name='zerver.views.create_realm'),
url(r'^create_realm/(?P<creation_key>[\w]+)$', zerver.views.registration.create_realm, name='zerver.views.create_realm'),
url(r'^create_realm/$', zerver.views.registration.create_realm,
name='zerver.views.create_realm'),
url(r'^create_realm/(?P<creation_key>[\w]+)$',
zerver.views.registration.create_realm, name='zerver.views.create_realm'),
# Login/registration
url(r'^register/$', zerver.views.registration.accounts_home, name='register'),
url(r'^login/$', zerver.views.auth.login_page, {'template_name': 'zerver/login.html'}, name='zerver.views.auth.login_page'),
url(r'^login/$', zerver.views.auth.login_page, {'template_name': 'zerver/login.html'},
name='zerver.views.auth.login_page'),
url(r'^join/(?P<confirmation_key>\S+)/$', zerver.views.registration.accounts_home_from_multiuse_invite,
url(r'^join/(?P<confirmation_key>\S+)/$',
zerver.views.registration.accounts_home_from_multiuse_invite,
name='zerver.views.registration.accounts_home_from_multiuse_invite'),
# API and integrations documentation
url(r'^api/$', APIView.as_view(template_name='zerver/api.html')),
url(r'^api/endpoints/$', zerver.views.integrations.api_endpoint_docs, name='zerver.views.integrations.api_endpoint_docs'),
url(r'^integrations/doc-html/(?P<integration_name>[^/]*)$', zerver.views.integrations.integration_doc,
url(r'^api/endpoints/$', zerver.views.integrations.api_endpoint_docs,
name='zerver.views.integrations.api_endpoint_docs'),
url(r'^integrations/doc-html/(?P<integration_name>[^/]*)$',
zerver.views.integrations.integration_doc,
name="zerver.views.integrations.integration_doc"),
url(r'^integrations/(.*)', IntegrationView.as_view()),
url(r'^about/$', zerver.views.users.about_view),
@ -408,7 +430,8 @@ i18n_urls = [
url(r'^why-zulip/$', TemplateView.as_view(template_name='zerver/why-zulip.html')),
url(r'^for/open-source/$', TemplateView.as_view(template_name='zerver/for-open-source.html')),
url(r'^for/companies/$', TemplateView.as_view(template_name='zerver/for-companies.html')),
url(r'^for/working-groups-and-communities/$', TemplateView.as_view(template_name='zerver/for-working-groups-and-communities.html')),
url(r'^for/working-groups-and-communities/$',
TemplateView.as_view(template_name='zerver/for-working-groups-and-communities.html')),
# Terms of Service and privacy pages.
url(r'^terms/$', TemplateView.as_view(template_name='zerver/terms.html'), name='terms'),
@ -467,19 +490,23 @@ urls += [
# like the requested subdomains'd realm icon (if known).
url(r'^api/v1/server_settings', zerver.views.auth.api_get_server_settings),
# This is a deprecated old version of api/v1/server_settings that only returns auth backends.
url(r'^api/v1/get_auth_backends', zerver.views.auth.api_get_auth_backends, name='zerver.views.auth.api_get_auth_backends'),
url(r'^api/v1/get_auth_backends', zerver.views.auth.api_get_auth_backends,
name='zerver.views.auth.api_get_auth_backends'),
# used by mobile apps to check if they are compatible with the server
url(r'^compatibility$', zerver.views.compatibility.check_compatibility),
# This json format view used by the mobile apps accepts a username
# password/pair and returns an API key.
url(r'^api/v1/fetch_api_key$', zerver.views.auth.api_fetch_api_key, name='zerver.views.auth.api_fetch_api_key'),
url(r'^api/v1/fetch_api_key$', zerver.views.auth.api_fetch_api_key,
name='zerver.views.auth.api_fetch_api_key'),
# This is for the signing in through the devAuthBackEnd on mobile apps.
url(r'^api/v1/dev_fetch_api_key$', zerver.views.auth.api_dev_fetch_api_key, name='zerver.views.auth.api_dev_fetch_api_key'),
url(r'^api/v1/dev_fetch_api_key$', zerver.views.auth.api_dev_fetch_api_key,
name='zerver.views.auth.api_dev_fetch_api_key'),
# This is for fetching the emails of the admins and the users.
url(r'^api/v1/dev_get_emails$', zerver.views.auth.api_dev_get_emails, name='zerver.views.auth.api_dev_get_emails'),
url(r'^api/v1/dev_get_emails$', zerver.views.auth.api_dev_get_emails,
name='zerver.views.auth.api_dev_get_emails'),
# Used to present the GOOGLE_CLIENT_ID to mobile apps
url(r'^api/v1/fetch_google_client_id$',