Skip to content

Commit 2ebf587

Browse files
Apply explicit __init__ workaround to AnnotatedString (#465)
* Convert `emails` to `annotated_emails` * Add explicit __init__ for `AnnotatedString`
1 parent f061efa commit 2ebf587

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/electionguard/manifest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class VoteVariationType(Enum):
8888
other = "other"
8989

9090

91+
# pylint: disable=super-init-not-called
9192
@dataclass(eq=True, unsafe_hash=True)
9293
class AnnotatedString(CryptoHashable):
9394
"""
@@ -98,6 +99,16 @@ class AnnotatedString(CryptoHashable):
9899
annotation: str = field(default="")
99100
value: str = field(default="")
100101

102+
# explicit `__init__` added as workaround for https://bugs.python.org/issue45081
103+
# can potentially be removed with future python version >3.9.7
104+
def __init__(
105+
self,
106+
annotation: str = "",
107+
value: str = "",
108+
):
109+
self.annotation = annotation
110+
self.value = value
111+
101112
def crypto_hash(self) -> ElementModQ:
102113
"""
103114
A hash representation of the object

src/electionguard_tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
from electionguard_tools.strategies import (
7070
CIPHERTEXT_ELECTIONS_TUPLE_TYPE,
7171
ELECTIONS_AND_BALLOTS_TUPLE_TYPE,
72+
annotated_emails,
7273
annotated_strings,
7374
ballot_styles,
7475
candidate_contest_descriptions,
@@ -133,6 +134,7 @@
133134
"TALLY_FILE_NAME",
134135
"TallyCeremonyOrchestrator",
135136
"accumulate_plaintext_ballots",
137+
"annotated_emails",
136138
"annotated_strings",
137139
"ballot_factory",
138140
"ballot_styles",

src/electionguard_tools/strategies/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from electionguard_tools.strategies.election import (
66
CIPHERTEXT_ELECTIONS_TUPLE_TYPE,
77
ELECTIONS_AND_BALLOTS_TUPLE_TYPE,
8+
annotated_emails,
89
annotated_strings,
910
ballot_styles,
1011
candidate_contest_descriptions,
@@ -42,6 +43,7 @@
4243
__all__ = [
4344
"CIPHERTEXT_ELECTIONS_TUPLE_TYPE",
4445
"ELECTIONS_AND_BALLOTS_TUPLE_TYPE",
46+
"annotated_emails",
4547
"annotated_strings",
4648
"ballot_styles",
4749
"candidate_contest_descriptions",

src/electionguard_tools/strategies/election.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def contact_infos(draw: _DrawType):
182182
:param draw: Hidden argument, used by Hypothesis.
183183
"""
184184
# empty lists for email and phone, for now
185-
return ContactInformation(None, draw(emails()), None, draw(human_names()))
185+
return ContactInformation(None, draw(annotated_emails()), None, draw(human_names()))
186186

187187

188188
@composite
@@ -257,6 +257,16 @@ def annotated_strings(draw: _DrawType):
257257
return AnnotatedString(annotation=s.language, value=s.value)
258258

259259

260+
@composite
261+
def annotated_emails(draw: _DrawType):
262+
"""
263+
Generates an `AnnotatedString` object with one `Language` and an associated
264+
`value` string (representing an annotated email).
265+
:param draw: Hidden argument, used by Hypothesis.
266+
"""
267+
return AnnotatedString(value=draw(emails()))
268+
269+
260270
@composite
261271
def ballot_styles(
262272
draw: _DrawType, party_ids: List[Party], geo_units: List[GeopoliticalUnit]

0 commit comments

Comments
 (0)