mirror of https://github.com/zulip/zulip.git
mypy: Fix several Optional typing errors.
This commit is contained in:
parent
6d00d4d2b1
commit
b81fd407e8
|
@ -1937,7 +1937,7 @@ def do_change_default_sending_stream(user_profile, stream, log=True):
|
|||
'stream': str(stream)})
|
||||
if user_profile.is_bot:
|
||||
if stream:
|
||||
stream_name = stream.name
|
||||
stream_name = stream.name # type: Optional[Text]
|
||||
else:
|
||||
stream_name = None
|
||||
send_event(dict(type='realm_bot',
|
||||
|
@ -1960,7 +1960,7 @@ def do_change_default_events_register_stream(user_profile, stream, log=True):
|
|||
'stream': str(stream)})
|
||||
if user_profile.is_bot:
|
||||
if stream:
|
||||
stream_name = stream.name
|
||||
stream_name = stream.name # type: Optional[Text]
|
||||
else:
|
||||
stream_name = None
|
||||
send_event(dict(type='realm_bot',
|
||||
|
|
|
@ -26,7 +26,7 @@ def random_api_key():
|
|||
# Recipient objects
|
||||
def create_user_profile(realm, email, password, active, bot_type, full_name,
|
||||
short_name, bot_owner, is_mirror_dummy, tos_version):
|
||||
# type: (Realm, Text, Text, bool, Optional[int], Text, Text, Optional[UserProfile], bool, Optional[Text]) -> UserProfile
|
||||
# type: (Realm, Text, Optional[Text], bool, Optional[int], Text, Text, Optional[UserProfile], bool, Optional[Text]) -> UserProfile
|
||||
now = timezone.now()
|
||||
email = UserManager.normalize_email(email)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ ParamsT = Union[Iterable[Any], Mapping[Text, Any]]
|
|||
# Similar to the tracking done in Django's CursorDebugWrapper, but done at the
|
||||
# psycopg2 cursor level so it works with SQLAlchemy.
|
||||
def wrapper_execute(self, action, sql, params=()):
|
||||
# type: (CursorObj, Callable[[NonBinaryStr, Optional[ParamsT]], CursorObj], NonBinaryStr, ParamsT) -> CursorObj
|
||||
# type: (CursorObj, Callable[[NonBinaryStr, Optional[ParamsT]], CursorObj], NonBinaryStr, Optional[ParamsT]) -> CursorObj
|
||||
start = time.time()
|
||||
try:
|
||||
return action(sql, params)
|
||||
|
|
|
@ -14,7 +14,7 @@ from typing import Optional
|
|||
# setup, which we might want if we move Tornado to run in a daemon
|
||||
# rather than via screen).
|
||||
def interactive_debug(sig, frame):
|
||||
# type: (int, Optional[FrameType]) -> None
|
||||
# type: (int, FrameType) -> None
|
||||
"""Interrupt running process, and provide a python prompt for
|
||||
interactive debugging."""
|
||||
d = {'_frame': frame} # Allow access to frame object.
|
||||
|
|
|
@ -83,11 +83,11 @@ def _check_hash(target_hash_file, **options):
|
|||
with open(target_hash_file) as f:
|
||||
target_hash_content = hashlib.sha1(f.read().encode('utf8')).hexdigest()
|
||||
|
||||
if os.path.exists(source_hash_file):
|
||||
if not os.path.exists(source_hash_file):
|
||||
source_hash_content = None
|
||||
else:
|
||||
with open(source_hash_file) as f:
|
||||
source_hash_content = f.read().strip()
|
||||
else:
|
||||
source_hash_content = None
|
||||
|
||||
with open(source_hash_file, 'w') as f:
|
||||
f.write(target_hash_content)
|
||||
|
@ -99,7 +99,7 @@ def is_template_database_current(
|
|||
migration_status='var/migration-status',
|
||||
settings='zproject.test_settings',
|
||||
check_files=None):
|
||||
# type: (Optional[Text], Optional[Text], Optional[Text], Optional[List[str]]) -> bool
|
||||
# type: (Text, Text, Text, Optional[List[str]]) -> bool
|
||||
# Using str type for check_files because re.split doesn't accept unicode
|
||||
if check_files is None:
|
||||
check_files = [
|
||||
|
|
|
@ -104,14 +104,14 @@ def simulated_empty_cache():
|
|||
cache_queries = [] # type: List[Tuple[str, Union[Text, List[Text]], Text]]
|
||||
|
||||
def my_cache_get(key, cache_name=None):
|
||||
# type: (Text, Optional[str]) -> Any
|
||||
# type: (Text, Optional[str]) -> Optional[Dict[Text, Any]]
|
||||
cache_queries.append(('get', key, cache_name))
|
||||
return None
|
||||
|
||||
def my_cache_get_many(keys, cache_name=None):
|
||||
# type: (List[Text], Optional[str]) -> Dict[Text, Any]
|
||||
cache_queries.append(('getmany', keys, cache_name))
|
||||
return None
|
||||
return {}
|
||||
|
||||
old_get = cache.cache_get
|
||||
old_get_many = cache.cache_get_many
|
||||
|
|
|
@ -111,7 +111,7 @@ def check_variable_type(allowed_type_funcs):
|
|||
types for this variable.
|
||||
"""
|
||||
def enumerated_type_check(var_name, val):
|
||||
# type: (str, Any) -> str
|
||||
# type: (str, Any) -> Optional[str]
|
||||
for func in allowed_type_funcs:
|
||||
if not func(var_name, val):
|
||||
return None
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from typing import Optional
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
|
@ -32,7 +33,7 @@ class AdminZulipHandler(logging.Handler):
|
|||
exception_filter = get_exception_reporter_filter(request)
|
||||
|
||||
if record.exc_info:
|
||||
stack_trace = ''.join(traceback.format_exception(*record.exc_info))
|
||||
stack_trace = ''.join(traceback.format_exception(*record.exc_info)) # type: Optional[str]
|
||||
else:
|
||||
stack_trace = None
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ def write_log_line(log_data, path, method, remote_ip, email, client_name,
|
|||
if error_content is not None:
|
||||
error_content_iter = (error_content,)
|
||||
|
||||
# For statsd timer name
|
||||
# For statsd timer name
|
||||
if path == '/':
|
||||
statsd_path = u'webreq'
|
||||
else:
|
||||
|
@ -217,6 +217,7 @@ def write_log_line(log_data, path, method, remote_ip, email, client_name,
|
|||
|
||||
# Log some additional data whenever we return certain 40x errors
|
||||
if 400 <= status_code < 500 and status_code not in [401, 404, 405]:
|
||||
assert error_content_iter is not None
|
||||
error_content_list = list(error_content_iter)
|
||||
if error_content_list:
|
||||
error_data = u''
|
||||
|
|
|
@ -18,7 +18,7 @@ def list_emoji(request, user_profile):
|
|||
return json_success({'emoji': user_profile.realm.get_emoji()})
|
||||
|
||||
@has_request_variables
|
||||
def upload_emoji(request, user_profile, emoji_name=None, url=REQ()):
|
||||
def upload_emoji(request, user_profile, emoji_name, url=REQ()):
|
||||
# type: (HttpRequest, UserProfile, Text, Text) -> HttpResponse
|
||||
check_valid_emoji_name(emoji_name)
|
||||
check_emoji_admin(user_profile)
|
||||
|
|
Loading…
Reference in New Issue