Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit c43dd4d

Browse files
author
David Robertson
authored
Deal with mypy errors w/ type-hinted pynacl 1.5.0 (#11714)
* Deal with mypy errors w/ type-hinted pynacl 1.5.0 Fixes #11644. I really don't like that we're monkey patching pynacl SignedKey instances with alg and version objects. But I'm too scared to make the changes necessary right now. (Ideally I would replace `signedjson.types.SingingKey` with a runtime class which wraps or inherits from `nacl.signing.SigningKey`.) C.f. matrix-org/python-signedjson#16
1 parent 3be6365 commit c43dd4d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

changelog.d/11714.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a typechecker problem related to our (ab)use of `nacl.signing.SigningKey`s.

tests/crypto/test_event_signing.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
import nacl.signing
17+
import signedjson.types
1718
from unpaddedbase64 import decode_base64
1819

1920
from synapse.api.room_versions import RoomVersions
@@ -35,7 +36,12 @@
3536

3637
class EventSigningTestCase(unittest.TestCase):
3738
def setUp(self):
38-
self.signing_key = nacl.signing.SigningKey(SIGNING_KEY_SEED)
39+
# NB: `signedjson` expects `nacl.signing.SigningKey` instances which have been
40+
# monkeypatched to include new `alg` and `version` attributes. This is captured
41+
# by the `signedjson.types.SigningKey` protocol.
42+
self.signing_key: signedjson.types.SigningKey = nacl.signing.SigningKey(
43+
SIGNING_KEY_SEED
44+
)
3945
self.signing_key.alg = KEY_ALG
4046
self.signing_key.version = KEY_VER
4147

0 commit comments

Comments
 (0)