Update typing hints for Mypy 1.1.1

Due to a bump in our Python dependencies, we now install Mypy 1.1.1
instead of 0.982. This change triggered the following errors:

* Incompatible default for argument <a> (default has type
  None, argument has type <t>):

  Mypy further explains here that PEP 484 prohibits implicit Optional,
  so we need to make these types explicit Optional.

* Unused "type: ignore" comment, use narrower [method-assign] instead of
  [assignment]:

  Mypy has specialized some of its lints, meaning that we should switch
  to the newer variants.

Also, it detected several other small inconsistencies. We fix all of
these errors in this commit.
This commit is contained in:
Alex Pyrgiotis 2023-03-27 15:07:40 +03:00
parent 1f308e9cc5
commit 8b846820d2
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
8 changed files with 18 additions and 14 deletions

View file

@ -30,7 +30,9 @@ TIMEOUT_PER_MB: float = 30 # (seconds)
TIMEOUT_MIN: float = 60 # (seconds)
async def read_stream(sr: asyncio.StreamReader, callback: Callable = None) -> bytes:
async def read_stream(
sr: asyncio.StreamReader, callback: Optional[Callable] = None
) -> bytes:
"""Consume a byte stream line-by-line.
Read all lines in a stream until EOF. If a user has passed a callback, call it for
@ -59,8 +61,8 @@ async def run_command(
error_message: str,
timeout_message: str,
timeout: Optional[float],
stdout_callback: Callable = None,
stderr_callback: Callable = None,
stdout_callback: Optional[Callable] = None,
stderr_callback: Optional[Callable] = None,
) -> Tuple[bytes, bytes]:
"""Run a command and get its output.

View file

@ -105,4 +105,4 @@ def override_parser_and_check_suspicious_options(click_main: click.Command) -> N
check_suspicious_options(args)
return orig_parse_fn(ctx, args)
click_main.parse_args = custom_parse_fn # type: ignore [assignment]
click_main.parse_args = custom_parse_fn # type: ignore [method-assign]

View file

@ -33,8 +33,8 @@ class Document:
def __init__(
self,
input_filename: str = None,
output_filename: str = None,
input_filename: Optional[str] = None,
output_filename: Optional[str] = None,
suffix: str = SAFE_EXTENSION,
archive: bool = False,
) -> None:

View file

@ -55,7 +55,7 @@ class Application(QtWidgets.QApplication):
return self.original_event(event)
self.event = monkeypatch_event # type: ignore [assignment]
self.event = monkeypatch_event # type: ignore [method-assign]
@click.command()

View file

@ -6,7 +6,7 @@ import shlex
import subprocess
import typing
from pathlib import Path
from typing import Dict
from typing import Dict, Optional
from colorama import Fore
@ -129,7 +129,7 @@ class Alert(QtWidgets.QDialog):
message: str,
ok_text: str = "Ok",
has_cancel: bool = True,
extra_button_text: str = None,
extra_button_text: Optional[str] = None,
) -> None:
super(Alert, self).__init__()
self.dangerzone = dangerzone

View file

@ -665,7 +665,7 @@ class ConvertTask(QtCore.QObject):
self,
dangerzone: DangerzoneGui,
document: Document,
ocr_lang: str = None,
ocr_lang: Optional[str] = None,
) -> None:
super(ConvertTask, self).__init__()
self.document = document

View file

@ -28,7 +28,7 @@ class Dummy(IsolationProvider):
)
def install(self) -> bool:
pass
return True
def _convert(
self,

View file

@ -9,7 +9,7 @@ import sys
import tempfile
import traceback
from pathlib import Path
from typing import Sequence
from typing import Optional, Sequence
from unittest import mock
import pytest
@ -56,7 +56,9 @@ class CLIResult(Result):
self.print_info()
raise
def assert_failure(self, exit_code: int = None, message: str = None) -> None:
def assert_failure(
self, exit_code: Optional[int] = None, message: Optional[str] = None
) -> None:
"""Assert that the command failed.
By default, check that the command has returned with an exit code
@ -111,7 +113,7 @@ class CLIResult(Result):
class TestCli(TestBase):
def run_cli(
self, args: Sequence[str] | str = (), tmp_path: Path = None
self, args: Sequence[str] | str = (), tmp_path: Optional[Path] = None
) -> CLIResult:
"""Run the CLI with the provided arguments.