mypy: Change six.text_type to typing.Text for a few files.

Preparation for GCI.
This commit is contained in:
Rishi Gupta 2016-11-22 19:53:54 -08:00 committed by Tim Abbott
parent 0e7899d170
commit 17f71befb4
6 changed files with 20 additions and 26 deletions

View File

@ -1,5 +1,5 @@
from __future__ import absolute_import
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, Text
#!/usr/bin/env python
# This file is adapted from samples/shellinabox/ssh-krb-wrapper in
@ -91,7 +91,7 @@ def der_encode_uint32(val):
return der_encode_integer(val)
def der_encode_string(val):
# type: (six.text_type) -> str
# type: (Text) -> str
if not isinstance(val, six.text_type):
raise TypeError("unicode")
return der_encode_tlv(0x1b, val.encode("utf-8"))

View File

@ -32,13 +32,13 @@ It is recommended to use the utility functions for other string conversions.
import six
from six import text_type, binary_type
from typing import Any, Mapping, Union, TypeVar
from typing import Any, Mapping, Union, TypeVar, Text
NonBinaryStr = TypeVar('NonBinaryStr', str, text_type)
# This is used to represent text or native strings
def force_text(s, encoding='utf-8'):
# type: (Union[text_type, binary_type], str) -> text_type
# type: (Union[Text, binary_type], str) -> Text
"""converts a string to a text string"""
if isinstance(s, text_type):
return s
@ -48,7 +48,7 @@ def force_text(s, encoding='utf-8'):
raise TypeError("force_text expects a string type")
def force_bytes(s, encoding='utf-8'):
# type: (Union[text_type, binary_type], str) -> binary_type
# type: (Union[Text, binary_type], str) -> binary_type
"""converts a string to binary string"""
if isinstance(s, binary_type):
return s
@ -58,7 +58,7 @@ def force_bytes(s, encoding='utf-8'):
raise TypeError("force_bytes expects a string type")
def force_str(s, encoding='utf-8'):
# type: (Union[text_type, binary_type], str) -> str
# type: (Union[Text, binary_type], str) -> str
"""converts a string to a native string"""
if isinstance(s, str):
return s
@ -82,7 +82,7 @@ class ModelReprMixin(object):
This mixin will automatically define __str__ and __repr__.
"""
def __unicode__(self):
# type: () -> text_type
# type: () -> Text
# Originally raised an exception, but Django (e.g. the ./manage.py shell)
# was catching the exception and not displaying any sort of error
return u"Implement __unicode__ in your subclass of ModelReprMixin!"

View File

@ -1,7 +1,6 @@
# Webhooks for external integrations.
from __future__ import absolute_import
import six
from typing import Dict, Any
from typing import Dict, Any, Text
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
@ -9,8 +8,6 @@ from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import Client, UserProfile
import six
AIRBRAKE_SUBJECT_TEMPLATE = '{project_name}'
AIRBRAKE_MESSAGE_TEMPLATE = '[{error_class}]({error_url}): "{error_message}" occurred.'
@ -18,7 +15,7 @@ AIRBRAKE_MESSAGE_TEMPLATE = '[{error_class}]({error_url}): "{error_message}" occ
@has_request_variables
def api_airbrake_webhook(request, user_profile, client, payload=REQ(argument_type='body'),
stream=REQ(default='airbrake')):
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], six.text_type) -> HttpResponse
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse
try:
subject = get_subject(payload)
body = get_body(payload)

View File

@ -10,8 +10,7 @@ from django.http import HttpRequest, HttpResponse
import pprint
import ujson
import six
from typing import Dict, Any, Iterable, Optional
from typing import Dict, Any, Iterable, Optional, Text
PAGER_DUTY_EVENT_NAMES = {
@ -71,7 +70,7 @@ def build_pagerduty_formatdict(message):
def send_raw_pagerduty_json(user_profile, client, stream, message, topic):
# type: (UserProfile, Client, six.text_type, Dict[str, Any], six.text_type) -> None
# type: (UserProfile, Client, Text, Dict[str, Any], Text) -> None
subject = topic or 'pagerduty'
body = (
u'Unknown pagerduty message\n'
@ -83,7 +82,7 @@ def send_raw_pagerduty_json(user_profile, client, stream, message, topic):
def send_formated_pagerduty(user_profile, client, stream, message_type, format_dict, topic):
# type: (UserProfile, Client, six.text_type, six.text_type, Dict[str, Any], six.text_type) -> None
# type: (UserProfile, Client, Text, Text, Dict[str, Any], Text) -> None
if message_type in ('incident.trigger', 'incident.unacknowledge'):
template = (u':imp: Incident '
u'[{incident_num}]({incident_url}) {action} by '
@ -112,7 +111,7 @@ def send_formated_pagerduty(user_profile, client, stream, message_type, format_d
@has_request_variables
def api_pagerduty_webhook(request, user_profile, client, payload=REQ(argument_type='body'),
stream=REQ(default='pagerduty'), topic=REQ(default=None)):
# type: (HttpRequest, UserProfile, Client, Dict[str, Iterable[Dict[str, Any]]], six.text_type, Optional[six.text_type]) -> HttpResponse
# type: (HttpRequest, UserProfile, Client, Dict[str, Iterable[Dict[str, Any]]], Text, Optional[Text]) -> HttpResponse
for message in payload['messages']:
message_type = message['type']

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from __future__ import absolute_import
from typing import Any
from typing import Any, Text
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
@ -11,7 +11,6 @@ from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_vi
from zerver.models import Client, UserProfile
import ujson
import six
PINGDOM_SUBJECT_TEMPLATE = '{name} status.'
@ -37,7 +36,7 @@ SUPPORTED_CHECK_TYPES = (
@has_request_variables
def api_pingdom_webhook(request, user_profile, client, payload=REQ(argument_type='body'),
stream=REQ(default='pingdom')):
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], six.text_type) -> HttpResponse
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse
check_type = get_check_type(payload)
if check_type in SUPPORTED_CHECK_TYPES:
@ -51,12 +50,12 @@ def api_pingdom_webhook(request, user_profile, client, payload=REQ(argument_type
def get_subject_for_http_request(payload):
# type: (Dict[str, Any]) -> six.text_type
# type: (Dict[str, Any]) -> Text
return PINGDOM_SUBJECT_TEMPLATE.format(name=payload['check_name'])
def get_body_for_http_request(payload):
# type: (Dict[str, Any]) -> six.text_type
# type: (Dict[str, Any]) -> Text
current_state = payload['current_state']
previous_state = payload['previous_state']
@ -74,5 +73,5 @@ def get_body_for_http_request(payload):
def get_check_type(payload):
# type: (Dict[str, Any]) -> six.text_type
# type: (Dict[str, Any]) -> Text
return payload['check_type']

View File

@ -19,7 +19,7 @@ subject of US/task should be in bold.
"""
from __future__ import absolute_import
from typing import Any, Mapping, Optional, Tuple
from typing import Any, Mapping, Optional, Tuple, Text
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
@ -31,14 +31,13 @@ from zerver.models import UserProfile, Client
import ujson
from six.moves import range
import six
@api_key_only_webhook_view('Taiga')
@has_request_variables
def api_taiga_webhook(request, user_profile, client, message=REQ(argument_type='body'),
stream=REQ(default='taiga'), topic=REQ(default='General')):
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], six.text_type, six.text_type) -> HttpResponse
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text, Text) -> HttpResponse
parsed_events = parse_message(message)
content_lines = []