mypy: Add --disallow-any=generics & extend typing accordingly.

Also reset typing of ExternalBotHandler to Any after discussion.
This commit is contained in:
neiljp (Neil Pilgrim) 2017-12-11 13:30:47 -08:00 committed by showell
parent 424a4bb631
commit 28687f18ca
10 changed files with 54 additions and 51 deletions

View file

@ -301,10 +301,10 @@ class ZulipToJabberBot(object):
def get_rooms(zulipToJabber):
# type: (ZulipToJabberBot) -> List[str]
def get_stream_infos(key, method):
# type: (str, Callable) -> Any
# type: (str, Callable[[], Dict[str, Any]]) -> Any
ret = method()
if ret.get("result") != "success":
logging.error(ret)
logging.error(str(ret))
sys.exit("Could not get initial list of Zulip %s" % (key,))
return ret[key]

View file

@ -252,7 +252,7 @@ def maybe_restart_mirroring_script():
time.sleep(1)
def process_loop(log):
# type: (IO) -> None
# type: (IO[Any]) -> None
restart_check_count = 0
last_check_time = time.time()
while True:
@ -362,7 +362,7 @@ def decrypt_zephyr(zephyr_class, instance, body):
return decrypted
def process_notice(notice, log):
# type: (zulip, IO) -> None
# type: (zulip, IO[Any]) -> None
(zsig, body) = parse_zephyr_body(notice.message, notice.format)
is_personal = False
is_huddle = False
@ -579,7 +579,7 @@ def zephyr_to_zulip(options):
process_loop(None)
def send_zephyr(zwrite_args, content):
# type: (List, str) -> Tuple[int, str]
# type: (List[str], str) -> Tuple[int, str]
p = subprocess.Popen(zwrite_args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate(input=content.encode("utf-8"))
@ -969,7 +969,7 @@ def configure_logger(logger, direction_name):
handler.setFormatter(formatter)
def parse_args():
# type: () -> Tuple
# type: () -> Tuple[Any, ...]
parser = optparse.OptionParser()
parser.add_option('--forward-class-messages',
default=False,

View file

@ -435,7 +435,7 @@ class Client(object):
)
def do_api_query(self, orig_request, url, method="POST", longpolling=False, files=None):
# type: (Mapping[str, Any], str, str, bool, List[IO]) -> Dict[str, Any]
# type: (Mapping[str, Any], str, str, bool, List[IO[Any]]) -> Dict[str, Any]
if files is None:
files = []
@ -568,14 +568,14 @@ class Client(object):
"status_code": res.status_code}
def call_endpoint(self, url=None, method="POST", request=None, longpolling=False, files=None):
# type: (str, str, Dict[str, Any], bool, List[IO]) -> Dict[str, Any]
# type: (str, str, Dict[str, Any], bool, List[IO[Any]]) -> Dict[str, Any]
if request is None:
request = dict()
return self.do_api_query(request, API_VERSTRING + url, method=method,
longpolling=longpolling, files=files)
def call_on_each_event(self, callback, event_types=None, narrow=None):
# type: (Callable, Optional[List[str]], Any) -> None
# type: (Callable[[Any], None], Optional[List[str]], Any) -> None
if narrow is None:
narrow = []
@ -635,7 +635,7 @@ class Client(object):
callback(event)
def call_on_each_message(self, callback):
# type: (Callable) -> None
# type: (Callable[[Any], None]) -> None
def event_callback(event):
# type: (Dict[str, str]) -> None
if event['type'] == 'message':
@ -653,7 +653,7 @@ class Client(object):
)
def upload_file(self, file):
# type: (IO) -> Dict[str, Any]
# type: (IO[Any]) -> Dict[str, Any]
'''
See examples/upload-file for example usage.
'''

View file

@ -25,7 +25,7 @@ from __future__ import print_function
import argparse
from six.moves import StringIO as _StringIO
from typing import IO
from typing import IO, Any
import zulip
class StringIO(_StringIO):
@ -47,7 +47,7 @@ options = parser.parse_args()
client = zulip.init_from_options(options)
file = None # type: IO
file = None # type: IO[Any]
if options.file_path:
file = open(options.file_path, 'rb')
else: