mypy: Add type ignores for mixing of str & bytes in zephyr mirror.

In principle these should be fixed properly, but the zephyr code is
difficult to test except in a production setting and is unlikely to be
heavily developed in future.
This commit is contained in:
neiljp (Neil Pilgrim) 2020-03-17 18:42:39 -07:00 committed by Tim Abbott
parent 520a004b85
commit 60984ab2fa
2 changed files with 11 additions and 9 deletions

View file

@ -112,7 +112,8 @@ def send_zephyr(zwrite_args, content):
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate(input=content.encode("utf-8")) stdout, stderr = p.communicate(input=content.encode("utf-8"))
if p.returncode != 0: if p.returncode != 0:
if "Detected server failure while receiving acknowledgement for" in stdout: # FIXME: This should really look for a byte form of the string in stdout
if "Detected server failure while receiving acknowledgement for" in stdout: # type: ignore
logger.warning("Got server failure error sending zephyr; retrying") logger.warning("Got server failure error sending zephyr; retrying")
logger.warning(stderr) logger.warning(stderr)
return True return True

View file

@ -335,10 +335,10 @@ def decrypt_zephyr(zephyr_class, instance, body):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
decrypted, _ = p.communicate(input=body) decrypted, _ = p.communicate(input=body) # type: ignore # Optional[bytes] vs string
# Restore our ignoring signals # Restore our ignoring signals
signal.signal(signal.SIGCHLD, signal.SIG_IGN) signal.signal(signal.SIGCHLD, signal.SIG_IGN)
return decrypted return decrypted # type: ignore # bytes, expecting str
def process_notice(notice, log): def process_notice(notice, log):
# type: (Any, Optional[IO[Any]]) -> None # type: (Any, Optional[IO[Any]]) -> None
@ -566,13 +566,13 @@ def send_zephyr(zwrite_args, content):
logger.error("zwrite command '%s' failed with return code %d:" % ( logger.error("zwrite command '%s' failed with return code %d:" % (
" ".join(zwrite_args), p.returncode,)) " ".join(zwrite_args), p.returncode,))
if stdout: if stdout:
logger.info("stdout: " + stdout) logger.info("stdout: " + stdout) # type: ignore # str + bytes
elif stderr: elif stderr:
logger.warning("zwrite command '%s' printed the following warning:" % ( logger.warning("zwrite command '%s' printed the following warning:" % (
" ".join(zwrite_args),)) " ".join(zwrite_args),))
if stderr: if stderr:
logger.warning("stderr: " + stderr) logger.warning("stderr: " + stderr) # type: ignore # str + bytes
return (p.returncode, stderr) return (p.returncode, stderr) # type: ignore # bytes vs str
def send_authed_zephyr(zwrite_args, content): def send_authed_zephyr(zwrite_args, content):
# type: (List[str], str) -> Tuple[int, str] # type: (List[str], str) -> Tuple[int, str]
@ -605,8 +605,8 @@ def zcrypt_encrypt_content(zephyr_class, instance, content):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
encrypted, _ = p.communicate(input=content) encrypted, _ = p.communicate(input=content) # type: ignore # Optional[bytes] vs string
return encrypted return encrypted # type: ignore # bytes, expecting Optional[str]
def forward_to_zephyr(message): def forward_to_zephyr(message):
# type: (Dict[str, Any]) -> None # type: (Dict[str, Any]) -> None
@ -688,7 +688,8 @@ Zulip users (like you) received it, Zephyr users did not.
if options.test_mode: if options.test_mode:
logger.debug("Would have forwarded: %s\n%s" % logger.debug("Would have forwarded: %s\n%s" %
(zwrite_args, wrapped_content.encode("utf-8"))) (zwrite_args, wrapped_content.encode("utf-8"))) # type: ignore
# NOTE: mypy indicates %s outputs the encoded wrapped_content as per %r
return return
(code, stderr) = send_authed_zephyr(zwrite_args, wrapped_content) (code, stderr) = send_authed_zephyr(zwrite_args, wrapped_content)