Skip to content

Commit f061efa

Browse files
Workaround for Python 3.9.7 operation (#458)
* Add explicit __init__ for `Manifest` * Add explicit __init__ for `InternationalizedText` * Add explicit __init__ for `ContactInformation` * Add explicit __init__ for `Language` * Disable super-init-not-called pylint warning for patch * Add comments to identify workaround for potential removal in future * Drop python patch-specific version requirement Co-authored-by: Keith Fung <[email protected]>
1 parent f3e2f09 commit f061efa

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- cron: "30 23 * * 1" # 2330 UTC Every Monday
1212

1313
env:
14-
PYTHON_VERSION: "3.9.5"
14+
PYTHON_VERSION: 3.9
1515
POETRY_PATH: "$HOME/.poetry/bin"
1616

1717
jobs:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [closed]
66

77
env:
8-
PYTHON_VERSION: "3.9.5"
8+
PYTHON_VERSION: 3.9
99
POETRY_PATH: "$HOME/.poetry/bin"
1010

1111
jobs:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ElectionGuard supports a variety of use cases. The Primary use case is to genera
3131

3232
## 💻 Requirements
3333

34-
- [Python 3.9.5](https://www.python.org/downloads/) is <ins>**required**</ins> to develop this SDK. If developer uses multiple versions of python, [pyenv](https://github.com/pyenv/pyenv) is suggested to assist version management.
34+
- [Python 3.9](https://www.python.org/downloads/) is <ins>**required**</ins> to develop this SDK. If developer uses multiple versions of python, [pyenv](https://github.com/pyenv/pyenv) is suggested to assist version management.
3535
- [GNU Make](https://www.gnu.org/software/make/manual/make.html) is used to simplify the commands and GitHub Actions. This approach is recommended to simplify the command line experience. This is built in for MacOS and Linux. For Windows, setup is simpler with [Chocolatey](https://chocolatey.org/install) and installing the provided [make package](https://chocolatey.org/packages/make). The other Windows option is [manually installing make](http://gnuwin32.sourceforge.net/packages/make.htm).
3636
- [Gmpy2](https://gmpy2.readthedocs.io/en/latest/) is used for [Arbitrary-precision arithmetic](https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic) which
3737
has its own [installation requirements (native C libraries)](https://gmpy2.readthedocs.io/en/latest/intro.html#installation) on Linux and MacOS. **⚠️ Note:** _This is not required for Windows since the gmpy2 precompiled libraries are provided._

src/electionguard/manifest.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def crypto_hash(self) -> ElementModQ:
107107
return hash
108108

109109

110+
# pylint: disable=super-init-not-called
110111
@dataclass(eq=True, unsafe_hash=True)
111112
class Language(CryptoHashable):
112113
"""
@@ -117,6 +118,16 @@ class Language(CryptoHashable):
117118
value: str
118119
language: str = field(default="en")
119120

121+
# explicit `__init__` added as workaround for https://bugs.python.org/issue45081
122+
# can potentially be removed with future python version >3.9.7
123+
def __init__(
124+
self,
125+
value: str,
126+
language: str = "en",
127+
):
128+
self.value = value
129+
self.language = language
130+
120131
def crypto_hash(self) -> ElementModQ:
121132
"""
122133
A hash representation of the object
@@ -126,6 +137,7 @@ def crypto_hash(self) -> ElementModQ:
126137
return hash
127138

128139

140+
# pylint: disable=super-init-not-called
129141
@dataclass(eq=True, unsafe_hash=True)
130142
class InternationalizedText(CryptoHashable):
131143
"""
@@ -135,6 +147,14 @@ class InternationalizedText(CryptoHashable):
135147

136148
text: List[Language] = field(default_factory=lambda: [])
137149

150+
# explicit `__init__` added as workaround for https://bugs.python.org/issue45081
151+
# can potentially be removed with future python version >3.9.7
152+
def __init__(
153+
self,
154+
text: List[Language] = None,
155+
):
156+
self.text = text if text else list()
157+
138158
def crypto_hash(self) -> ElementModQ:
139159
"""
140160
A hash representation of the object
@@ -144,6 +164,7 @@ def crypto_hash(self) -> ElementModQ:
144164
return hash
145165

146166

167+
# pylint: disable=super-init-not-called
147168
@dataclass(eq=True, unsafe_hash=True)
148169
class ContactInformation(CryptoHashable):
149170
"""
@@ -156,6 +177,20 @@ class ContactInformation(CryptoHashable):
156177
phone: Optional[List[AnnotatedString]] = field(default=None)
157178
name: Optional[str] = field(default=None)
158179

180+
# explicit `__init__` added as workaround for https://bugs.python.org/issue45081
181+
# can potentially be removed with future python version >3.9.7
182+
def __init__(
183+
self,
184+
address_line: Optional[List[str]] = None,
185+
email: Optional[List[AnnotatedString]] = None,
186+
phone: Optional[List[AnnotatedString]] = None,
187+
name: Optional[str] = None,
188+
):
189+
self.address_line = address_line
190+
self.email = email
191+
self.phone = phone
192+
self.name = name
193+
159194
def crypto_hash(self) -> ElementModQ:
160195
"""
161196
A hash representation of the object
@@ -517,7 +552,7 @@ def selection_for(self, selection_id: str) -> Optional[SelectionDescription]:
517552
return None
518553

519554

520-
# pylint: disable=too-many-instance-attributes
555+
# pylint: disable=too-many-instance-attributes,super-init-not-called
521556
@dataclass(unsafe_hash=True)
522557
class Manifest(CryptoHashable):
523558
"""
@@ -546,6 +581,36 @@ class Manifest(CryptoHashable):
546581
name: Optional[InternationalizedText] = field(default=None)
547582
contact_information: Optional[ContactInformation] = field(default=None)
548583

584+
# explicit `__init__` added as workaround for https://bugs.python.org/issue45081
585+
# can potentially be removed with future python version >3.9.7
586+
def __init__(
587+
self,
588+
election_scope_id: str,
589+
spec_version: str,
590+
type: ElectionType,
591+
start_date: datetime,
592+
end_date: datetime,
593+
geopolitical_units: List[GeopoliticalUnit],
594+
parties: List[Party],
595+
candidates: List[Candidate],
596+
contests: List[ContestDescription],
597+
ballot_styles: List[BallotStyle],
598+
name: Optional[InternationalizedText] = None,
599+
contact_information: Optional[ContactInformation] = None,
600+
):
601+
self.election_scope_id = election_scope_id
602+
self.spec_version = spec_version
603+
self.type = type
604+
self.start_date = start_date
605+
self.end_date = end_date
606+
self.geopolitical_units = geopolitical_units
607+
self.parties = parties
608+
self.candidates = candidates
609+
self.contests = contests
610+
self.ballot_styles = ballot_styles
611+
self.name = name
612+
self.contact_information = contact_information
613+
549614
def __eq__(self, other: Any) -> bool:
550615
return (
551616
isinstance(other, Manifest)

0 commit comments

Comments
 (0)