From 6e9694d688cbaba5f2c0f0d2aa7922caff3381a4 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 16 Oct 2020 18:24:21 +0200 Subject: [PATCH 1/3] Fix mypy error: auth handler "checkpw" internal function type mismatch (Wants bytes, got Union[bytes, str] due to context closure inheritance) --- synapse/handlers/auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 1d1ddc22454b..43ae64cc0e2f 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -1122,20 +1122,20 @@ async def validate_hash( Whether self.hash(password) == stored_hash. """ - def _do_validate_hash(): + def _do_validate_hash(checked_hash: bytes): # Normalise the Unicode in the password pw = unicodedata.normalize("NFKC", password) return bcrypt.checkpw( pw.encode("utf8") + self.hs.config.password_pepper.encode("utf8"), - stored_hash, + checked_hash, ) if stored_hash: if not isinstance(stored_hash, bytes): stored_hash = stored_hash.encode("ascii") - return await defer_to_thread(self.hs.get_reactor(), _do_validate_hash) + return await defer_to_thread(self.hs.get_reactor(), _do_validate_hash, stored_hash) else: return False From ae439ed739cc56ecc73e2d10a0074ee24ef1519a Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 16 Oct 2020 18:30:01 +0200 Subject: [PATCH 2/3] add news and fix typing --- changelog.d/8569.misc | 1 + synapse/handlers/auth.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog.d/8569.misc diff --git a/changelog.d/8569.misc b/changelog.d/8569.misc new file mode 100644 index 000000000000..8273484bc440 --- /dev/null +++ b/changelog.d/8569.misc @@ -0,0 +1 @@ +Fix mypy typing assertion error in `handlers/auth.py`. \ No newline at end of file diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 43ae64cc0e2f..8619fbb982f6 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -1135,7 +1135,9 @@ def _do_validate_hash(checked_hash: bytes): if not isinstance(stored_hash, bytes): stored_hash = stored_hash.encode("ascii") - return await defer_to_thread(self.hs.get_reactor(), _do_validate_hash, stored_hash) + return await defer_to_thread( + self.hs.get_reactor(), _do_validate_hash, stored_hash + ) else: return False From 0d5b518a873a6bf9009b2fb964031743501a4841 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Fri, 16 Oct 2020 21:18:31 +0200 Subject: [PATCH 3/3] Make mypy respect some more checking rules by installing all dependencies --- changelog.d/8569.misc | 2 +- tox.ini | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/changelog.d/8569.misc b/changelog.d/8569.misc index 8273484bc440..3b6e0625e57e 100644 --- a/changelog.d/8569.misc +++ b/changelog.d/8569.misc @@ -1 +1 @@ -Fix mypy typing assertion error in `handlers/auth.py`. \ No newline at end of file +Fix mypy not properly checking across the codebase, additionally, fix a typing assertion error in `handlers/auth.py`. \ No newline at end of file diff --git a/tox.ini b/tox.ini index 4d132eff4cab..6d08153782aa 100644 --- a/tox.ini +++ b/tox.ini @@ -158,7 +158,6 @@ commands= coverage html [testenv:mypy] -skip_install = True deps = {[base]deps} mypy==0.782