Configure mypy to run in virtual environment and fix resulting issues (#989)

For some time I've noticed that my IDE is reporting mypy errors that the
pre-commit hook is not picking up. This is because [mypy
mirror](https://github.com/pre-commit/mirrors-mypy) runs in an isolated
pre-commit environment which does not have dependencies installed and it
enables `--ignore-missing-imports` to avoid errors.

This is [advised against by
mypy](https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker)
for obvious reasons:

> We recommend avoiding --ignore-missing-imports if possible: it’s
equivalent to adding a # type: ignore to all unresolved imports in your
codebase.

This PR configures the mypy pre-commit hook to run in the virtual
environment and addresses the additional errors identified as a result.
It also introduces a minimal mypy config into the `pyproject.toml`

[mypy errors identified without the fixes in this
PR](https://github.com/user-attachments/files/15896693/mypyerrors.txt)
This commit is contained in:
Steven B
2024-06-19 14:07:59 +01:00
committed by GitHub
parent 5b7e59056c
commit 416d3118bf
17 changed files with 138 additions and 42 deletions

View File

@@ -38,7 +38,7 @@ from ..httpclient import HttpClient
),
(Exception(), KasaException, "Unable to query the device: "),
(
aiohttp.ServerFingerprintMismatch("exp", "got", "host", 1),
aiohttp.ServerFingerprintMismatch(b"exp", b"got", "host", 1),
KasaException,
"Unable to query the device: ",
),
@@ -84,7 +84,7 @@ async def test_httpclient_errors(mocker, error, error_raises, error_message, moc
client = HttpClient(DeviceConfig(host))
# Exceptions with parameters print with double quotes, without use single quotes
full_msg = (
"\(" # type: ignore
re.escape("(")
+ "['\"]"
+ re.escape(f"{error_message}{host}: {error}")
+ "['\"]"