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