From 3b31182ed21415503e1950dff2be998e9852382b Mon Sep 17 00:00:00 2001 From: Arie Bovenberg Date: Sat, 22 Jan 2022 10:10:11 +0100 Subject: 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. --- rsa/key.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rsa/key.py b/rsa/key.py index d4feb42..f800644 100644 --- a/rsa/key.py +++ b/rsa/key.py @@ -239,7 +239,7 @@ class PublicKey(AbstractKey): """ - __slots__ = ("n", "e") + __slots__ = () def __getitem__(self, key: str) -> int: return getattr(self, key) @@ -404,7 +404,7 @@ class PrivateKey(AbstractKey): """ - __slots__ = ("n", "e", "d", "p", "q", "exp1", "exp2", "coef") + __slots__ = ("d", "p", "q", "exp1", "exp2", "coef") def __init__(self, n: int, e: int, d: int, p: int, q: int) -> None: AbstractKey.__init__(self, n, e) -- cgit v1.2.1