Skip to content

Commit cae4fd0

Browse files
authored
Merge pull request #3 from bogdan-kulynych/master
Fix #2: Remove mutable default argument and comparisons
2 parents 130342f + a369d82 commit cae4fd0

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

LowCostDP3T.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727

2828
# Fixed global default broadcast key for ephID generation.
2929
BROADCAST_KEY = "Broadcast key"
30-
30+
3131
# Length of an epoch (in minutes).
3232
EPOCH_LENGTH = 15
3333

3434
# Number of epochs per day.
3535
NUM_EPOCHS_PER_DAY = 24*60//EPOCH_LENGTH
36-
36+
3737
# Duration key and contact history is kept (in days).
3838
RETENTION_PERIOD = 14
3939

@@ -136,7 +136,7 @@ def get_epoch(self, now):
136136
def get_current_ephID(self, now = None):
137137
''' Returns the current ephID
138138
'''
139-
if now == None:
139+
if now is None:
140140
now = datetime.now(timezone.utc)
141141
return self.ephIDs[self.get_epoch(now)]
142142

@@ -153,7 +153,7 @@ def __init__(self):
153153

154154
# Remote beacon management
155155
##########################
156-
def receive_scans(self, beacons = [], now = None):
156+
def receive_scans(self, beacons = None, now = None):
157157
''' Receive a set of new BLE beacons and process them.
158158
159159
Add the current received information to the observations for the
@@ -163,7 +163,10 @@ def receive_scans(self, beacons = [], now = None):
163163
beacons([]): list of received beacons.
164164
now(datetime): current time, override for mock testing.
165165
'''
166-
if now == None:
166+
if beacons is None:
167+
beacons = []
168+
169+
if now is None:
167170
now = datetime.now(timezone.utc)
168171

169172
timestamp = (now.hour*60 + now.minute)*60 + now.second
@@ -234,7 +237,7 @@ def check_infected(self, inf_SK0, date, now = None):
234237
date(str): date of SK_t (i.e., the t in the form 2020-04-23).
235238
now(datetime): current date for mock testing.
236239
'''
237-
if now == None:
240+
if now is None:
238241
now = datetime.now(timezone.utc)
239242
infect_date = datetime.strptime(date, "%Y-%m-%d")
240243
days_infected = (now-infect_date).days
@@ -273,4 +276,4 @@ def next_day(self):
273276
self.ctmgr.rotate_contacts()
274277

275278
def next_epoch(self):
276-
self.ctmgr.process_epoch()
279+
self.ctmgr.process_epoch()

0 commit comments

Comments
 (0)