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

Commit 3b31182

Browse files
ariebovenbergsybrenstuvel
authored andcommitted
Remove overlapping slots from AbstractKey subclasses
`PublicKey` and `PrivateKey` both define the `n` and `e` slots, which are already present in their base class. This reduces the benefits of having slots. ```shell $ slotscheck -m rsa -v ERROR: 'rsa.key:PrivateKey' defines overlapping slots. - e (rsa.key:AbstractKey) - n (rsa.key:AbstractKey) ERROR: 'rsa.key:PublicKey' defines overlapping slots. - e (rsa.key:AbstractKey) - n (rsa.key:AbstractKey) ``` The Python docs say: > If a class defines a slot also defined in a base class, the instance > variable defined by the base class slot is inaccessible (except by > retrieving its descriptor directly from the base class). This renders > the meaning of the program undefined.
1 parent 6391b1a commit 3b31182

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rsa/key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class PublicKey(AbstractKey):
239239
240240
"""
241241

242-
__slots__ = ("n", "e")
242+
__slots__ = ()
243243

244244
def __getitem__(self, key: str) -> int:
245245
return getattr(self, key)
@@ -404,7 +404,7 @@ class PrivateKey(AbstractKey):
404404
405405
"""
406406

407-
__slots__ = ("n", "e", "d", "p", "q", "exp1", "exp2", "coef")
407+
__slots__ = ("d", "p", "q", "exp1", "exp2", "coef")
408408

409409
def __init__(self, n: int, e: int, d: int, p: int, q: int) -> None:
410410
AbstractKey.__init__(self, n, e)

0 commit comments

Comments
 (0)