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

Commit 505c902

Browse files
keithrfunglprichar
andauthored
🐞 Refactor - CLI models should use dataclass instead of init (Election-Tech-Initiative#670)
dataclass autogenerates the exact same init since there is no specialization on these files. This shortens the classes down and simplifies constructors. Co-authored-by: Lee Richardson <[email protected]>
1 parent 5698e83 commit 505c902

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

src/electionguard_cli/cli_models/cli_decrypt_results.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1+
from dataclasses import dataclass
12
from typing import Dict
23
from electionguard.tally import CiphertextTally, PlaintextTally
34
from electionguard.type import BallotId
45
from electionguard.election_polynomial import LagrangeCoefficientsRecord
56

67

8+
@dataclass
79
class CliDecryptResults:
810
"""Responsible for holding the results of decrypting an election."""
911

10-
def __init__(
11-
self,
12-
plaintext_tally: PlaintextTally,
13-
plaintext_spoiled_ballots: Dict[BallotId, PlaintextTally],
14-
ciphertext_tally: CiphertextTally,
15-
lagrange_coefficients: LagrangeCoefficientsRecord,
16-
):
17-
self.plaintext_tally = plaintext_tally
18-
self.plaintext_spoiled_ballots = plaintext_spoiled_ballots
19-
self.ciphertext_tally = ciphertext_tally
20-
self.lagrange_coefficients = lagrange_coefficients
21-
2212
plaintext_tally: PlaintextTally
2313
plaintext_spoiled_ballots: Dict[BallotId, PlaintextTally]
2414
ciphertext_tally: CiphertextTally
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1+
from dataclasses import dataclass
2+
13
from electionguard.election import CiphertextElectionContext
24
from electionguard.manifest import InternalManifest
35

46

7+
@dataclass
58
class BuildElectionResults:
69
"""The results of building an election, more specifically an internal manifest and context."""
710

8-
def __init__(
9-
self, internal_manifest: InternalManifest, context: CiphertextElectionContext
10-
):
11-
self.internal_manifest = internal_manifest
12-
self.context = context
13-
1411
internal_manifest: InternalManifest
1512
context: CiphertextElectionContext
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1+
from dataclasses import dataclass
12
from typing import List
23
from electionguard.ballot import CiphertextBallot
34
from electionguard.encrypt import EncryptionDevice
45

56

7+
@dataclass
68
class EncryptResults:
79
"""Responsible for holding the results of encrypting votes in an election."""
810

9-
def __init__(
10-
self,
11-
device: EncryptionDevice,
12-
ciphertext_ballots: List[CiphertextBallot],
13-
):
14-
self.device = device
15-
self.ciphertext_ballots = ciphertext_ballots
16-
1711
device: EncryptionDevice
1812
ciphertext_ballots: List[CiphertextBallot]

0 commit comments

Comments
 (0)