Skip to content

Commit 146359f

Browse files
committed
merge master into branch
2 parents 627e11c + cda9b9f commit 146359f

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ jobs:
1212
- uses: psf/black@stable
1313
with:
1414
options: "--check"
15+
pylint unit_of_time
1516
test:
1617
name: run tests
1718
strategy:
1819
matrix:
1920
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
2021
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
python-version:
25+
- '3.9'
26+
- '3.10'
27+
- '3.11'
28+
- '3.12'
29+
- '3.13'
2130
steps:
2231
- uses: actions/checkout@v4
2332
- name: Set up Python
@@ -26,15 +35,25 @@ jobs:
2635
python-version: ${{ matrix.python-version }}
2736
- name: Run test
2837
run: |
38+
<<<<<<< HEAD
2939
pip install pytest-cov pytest-random-order
3040
pytest --random-order --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=unit_of_time timetest.py
41+
=======
42+
pip install pytest-cov
43+
pytest --junitxml=pytest.xml --cov-fail-under=100 --cov-report=term-missing:skip-covered --cov=unit_of_time timetest.py
44+
>>>>>>> origin/master
3145
- name: Coveralls
3246
uses: coverallsapp/github-action@v2
3347
build:
3448
runs-on: ubuntu-latest
3549
strategy:
3650
matrix:
37-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
51+
python-version:
52+
- '3.9'
53+
- '3.10'
54+
- '3.11'
55+
- '3.12'
56+
- '3.13'
3857
steps:
3958
- name: checkout code
4059
uses: actions/checkout@v4

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ build-backend = 'setuptools.build_meta:__legacy__'
1111
write_to = "unit_of_time/_version.py"
1212

1313
[tool.black]
14-
extend-exclude = '(.*/migrations/.*|setup)\.py'
14+
extend-exclude = '(.*/migrations/.*|setup)\.py'

timetest.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,8 @@ def test_to_int(self):
189189
self.assertEqual(tu.previous.previous.previous, 3 << tu)
190190
self.assertLess(tu.last_date, tu.next.first_date)
191191
self.assertLess(tu.previous.last_date, tu.first_date)
192-
self.assertEqual(
193-
(tu.next.first_date - tu.last_date), timedelta(days=1)
194-
)
195-
self.assertEqual(
196-
(tu.first_date - tu.previous.last_date), timedelta(days=1)
197-
)
192+
self.assertEqual((tu.next.first_date - tu.last_date), timedelta(days=1))
193+
self.assertEqual((tu.first_date - tu.previous.last_date), timedelta(days=1))
198194

199195
def test_repr(self):
200196
self.assertEqual("Week", repr(Week))

unit_of_time/__init__.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import math
33
from datetime import date, datetime, timedelta
44

5+
ONE_DAY = timedelta(days=1)
6+
57

68
ONE_DAY = timedelta(days=1)
79

@@ -123,9 +125,7 @@ def unit_register(self):
123125
result = TimeunitKindMeta._registered
124126
if result is None:
125127
result = {
126-
k.kind_int: k
127-
for k in TimeunitKindMeta._pre_registered
128-
if k.kind_int is not None
128+
k.kind_int: k for k in TimeunitKindMeta._pre_registered if k.kind_int is not None
129129
}
130130
TimeunitKindMeta._registered = result
131131
return result
@@ -167,18 +167,22 @@ def __int__(self):
167167
"""
168168
return self.kind_int
169169

170-
def __index__(self):
171-
return int(self)
170+
def __int__(cls):
171+
return cls.kind_int
172172

173-
def __hash__(self):
173+
def __index__(cls):
174+
return int(cls)
175+
176+
def __hash__(cls):
174177
"""
175178
Return the hash value of the time unit, based on its integer encoding.
176179
"""
177-
return hash(int(self))
180+
return hash(int(cls))
178181

179-
def __eq__(self, other):
182+
def __eq__(cls, other):
180183
"""
181-
Return True if this time unit kind is the same as another kind or matches the kind registered for the given integer.
184+
Return True if this time unit kind is the same as another kind or matches the
185+
kind registered for the given integer.
182186
183187
Parameters:
184188
other: Another kind instance or an integer representing a registered kind.
@@ -188,7 +192,7 @@ def __eq__(self, other):
188192
"""
189193
if isinstance(other, int):
190194
other = TimeunitKind.unit_register[other]
191-
return self is other
195+
return cls is other
192196

193197
def __call__(cls, dt):
194198
"""
@@ -200,8 +204,8 @@ def __call__(cls, dt):
200204
dt = dt.dt
201205
return Timeunit(cls, dt)
202206

203-
def __lt__(self, other):
204-
return self.kind_int < other.kind_int
207+
def __lt__(cls, other):
208+
return cls.kind_int < other.kind_int
205209

206210
def from_int(cls, val):
207211
mul = cls.multiplier
@@ -241,7 +245,8 @@ def get_next(cls, dt):
241245
"""
242246
Return the next time unit instance of this kind after the given date.
243247
244-
If a `Timeunit` is provided, its date is used. The returned instance represents the time unit immediately following the one containing `dt`.
248+
If a `Timeunit` is provided, its date is used. The returned instance
249+
represents the time unit immediately following the one containing `dt`.
245250
"""
246251
if isinstance(dt, Timeunit):
247252
dt = dt.dt
@@ -315,11 +320,11 @@ def _shift(cls, cur, dt, amount):
315320
if new_dt is not None:
316321
return cls(new_dt)
317322
if amount > 0:
318-
for i in range(amount):
323+
for _ in range(amount):
319324
cur = cur.next
320325
return cur
321326
elif amount < 0:
322-
for i in range(-amount):
327+
for _ in range(-amount):
323328
cur = cur.previous
324329
return cur
325330
else:
@@ -464,9 +469,7 @@ def truncate(cls, dt):
464469
@classmethod
465470
def _inner_shift(cls, cur, dt, amount):
466471
q_new = dt.year * 4 + amount + (dt.month - 1) // 3
467-
y = q_new // 4
468-
q = q_new % 4
469-
return date(q_new // 4, 3 * q + 1, 1)
472+
return date(q_new // 4, 3 * (q_new % 4) + 1, 1)
470473

471474
@classmethod
472475
def _next(cls, dt):
@@ -701,7 +704,8 @@ def date_range(self):
701704
@property
702705
def ancestors(self):
703706
"""
704-
Yields an infinite sequence of preceding time units, starting from the previous unit of this instance.
707+
Yields an infinite sequence of preceding time units, starting from the
708+
previous unit of this instance.
705709
706710
Each iteration yields the next earlier time unit of the same kind.
707711
"""
@@ -782,7 +786,8 @@ def __eq__(self, other):
782786
"""
783787
Return True if this Timeunit is equal to another Timeunit or an integer representation.
784788
785-
Equality is determined by matching both the kind and the truncated date. If `other` is an integer, it is first converted to a Timeunit instance.
789+
Equality is determined by matching both the kind and the truncated date.
790+
If `other` is an integer, it is first converted to a Timeunit instance.
786791
"""
787792
if isinstance(other, int):
788793
other = TimeunitKind.from_int(other)
@@ -840,6 +845,7 @@ def _get_range(cls, item):
840845
dt0, dt1 = item
841846
if isinstance(dt0, date) and isinstance(dt1, date):
842847
return item
848+
raise TypeError(f"Cannot interpret date range of type {type(item)}")
843849
except TypeError:
844850
pass
845851
raise TypeError(f"Item {item!r} has no date range.")
@@ -852,7 +858,8 @@ def overlaps_with(self, item):
852858
item: A date, Timeunit, or a tuple of two dates representing a date range.
853859
854860
Returns:
855-
bool: True if there is any overlap between this time unit and the specified range or unit; otherwise, False.
861+
bool: True if there is any overlap between this time unit and the specified range
862+
or unit; otherwise, False.
856863
"""
857864
frm0, to0 = self._get_range(item)
858865
frm, to = self.date_range

0 commit comments

Comments
 (0)