Skip to content

Commit bf0146d

Browse files
Merge pull request #601 from matthijskooijman/support-py3.5
2 parents 5a930a9 + b06b11c commit bf0146d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ https://snapcraft.io/hamster-snap
5353
### Install from sources
5454

5555
#### Dependencies
56-
56+
Hamster needs python 3.5 or newer (not included in below install
57+
commands). Older versions are not supported.
5758

5859
##### Debian-based
5960

src/hamster/lib/datetime.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ class time(pdt.time):
139139
def __new__(cls,
140140
hour=0, minute=0,
141141
second=0, microsecond=0,
142-
tzinfo=None, fold=0):
142+
tzinfo=None, **kwargs):
143143
# round down to zero seconds and microseconds
144144
return pdt.time.__new__(cls,
145145
hour=hour, minute=minute,
146146
second=0, microsecond=0,
147-
tzinfo=None, fold=fold)
147+
tzinfo=None, **kwargs)
148148

149149
@classmethod
150150
def _extract_time(cls, match, h="hour", m="minute"):
@@ -220,12 +220,12 @@ class datetime(pdt.datetime):
220220
def __new__(cls, year, month, day,
221221
hour=0, minute=0,
222222
second=0, microsecond=0,
223-
tzinfo=None, *, fold=0):
223+
tzinfo=None, **kwargs):
224224
# round down to zero seconds and microseconds
225225
return pdt.datetime.__new__(cls, year, month, day,
226226
hour=hour, minute=minute,
227227
second=0, microsecond=0,
228-
tzinfo=None, fold=fold)
228+
tzinfo=None, **kwargs)
229229

230230
def __add__(self, other):
231231
# python datetime.__add__ was not type stable prior to 3.8
@@ -234,11 +234,13 @@ def __add__(self, other):
234234
# similar to https://stackoverflow.com/q/51966126/3565696
235235
# __getnewargs_ex__ did not work, brute force required
236236
def __deepcopy__(self, memo):
237+
kwargs = {}
238+
if (hasattr(self, 'fold')):
239+
kwargs['fold'] = self.fold
237240
return datetime(self.year, self.month, self.day,
238241
self.hour, self.minute,
239242
self.second, self.microsecond,
240-
self.tzinfo, fold=self.fold)
241-
243+
self.tzinfo, **kwargs)
242244
__radd__ = __add__
243245

244246
def __sub__(self, other):
@@ -327,10 +329,13 @@ def from_day_time(cls, d: hday, t: time):
327329
@classmethod
328330
def from_pdt(cls, t):
329331
"""Convert python datetime to hamster datetime."""
332+
kwargs = {}
333+
if (hasattr(t, 'fold')):
334+
kwargs['fold'] = t.fold
330335
return cls(t.year, t.month, t.day,
331336
t.hour, t.minute,
332337
t.second, t.microsecond,
333-
t.tzinfo, fold=t.fold)
338+
t.tzinfo, **kwargs)
334339

335340
@classmethod
336341
def now(cls):
@@ -392,10 +397,13 @@ def pattern(cls, n=None):
392397

393398
def to_pdt(self):
394399
"""Convert to python datetime."""
400+
kwargs = {}
401+
if (hasattr(self, 'fold')):
402+
kwargs['fold'] = self.fold
395403
return pdt.datetime(self.year, self.month, self.day,
396404
self.hour, self.minute,
397405
self.second, self.microsecond,
398-
self.tzinfo, fold=self.fold)
406+
self.tzinfo, **kwargs)
399407

400408

401409
# outside class; need the class to be defined first

src/hamster/lib/fact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _set(self, **kwds):
232232
"""
233233
for attr, value in kwds.items():
234234
if not hasattr(self, attr):
235-
raise AttributeError(f"'{attr}' not found")
235+
raise AttributeError("'{attr}' not found".format(attr=attr))
236236
else:
237237
setattr(self, attr, value)
238238

0 commit comments

Comments
 (0)