Skip to content

Commit 7ce51ea

Browse files
authored
Merge pull request #13 from nolar/drop-python-39
Drop Python 3.9; rewrite to Python 3.10+ syntax
2 parents 5c252ed + f560ade commit 7ce51ea

6 files changed

Lines changed: 79 additions & 66 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
27+
python-version: [ "3.10", "3.11", "3.12" ]
2828
include:
2929
- python-version: "3.13"
3030
- python-version: "3.13"
@@ -64,7 +64,7 @@ jobs:
6464
strategy:
6565
fail-fast: false
6666
matrix:
67-
python-version: [ "pypy-3.9", "pypy-3.10", "pypy-3.11" ]
67+
python-version: [ "pypy-3.10", "pypy-3.11" ]
6868
name: Python ${{ matrix.python-version }}
6969
runs-on: ubuntu-24.04
7070
timeout-minutes: 5

.github/workflows/thorough.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
29+
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
3030
name: Python ${{ matrix.python-version }}
3131
runs-on: ubuntu-24.04
3232
timeout-minutes: 5
@@ -60,7 +60,7 @@ jobs:
6060
strategy:
6161
fail-fast: false
6262
matrix:
63-
python-version: [ "pypy-3.9", "pypy-3.10", "pypy-3.11" ]
63+
python-version: [ "pypy-3.10", "pypy-3.11" ]
6464
name: Python ${{ matrix.python-version }}
6565
runs-on: ubuntu-24.04
6666
timeout-minutes: 5

looptime/math.py

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,80 +34,92 @@ def __float__(self) -> float:
3434
#
3535

3636
def __eq__(self, other: object) -> bool:
37-
if isinstance(other, (int, float)):
38-
return round(self._value * self.__rr) == round(other * self.__rr)
39-
else:
40-
return NotImplemented
37+
match other:
38+
case int() | float():
39+
return round(self._value * self.__rr) == round(other * self.__rr)
40+
case _:
41+
return NotImplemented
4142

4243
def __ne__(self, other: object) -> bool:
43-
if isinstance(other, (int, float)):
44-
return round(self._value * self.__rr) != round(other * self.__rr)
45-
else:
46-
return NotImplemented
44+
match other:
45+
case int() | float():
46+
return round(self._value * self.__rr) != round(other * self.__rr)
47+
case _:
48+
return NotImplemented
4749

4850
def __ge__(self, other: object) -> bool:
49-
if isinstance(other, (int, float)):
50-
return round(self._value * self.__rr) >= round(other * self.__rr)
51-
else:
52-
return NotImplemented
51+
match other:
52+
case int() | float():
53+
return round(self._value * self.__rr) >= round(other * self.__rr)
54+
case _:
55+
return NotImplemented
5356

5457
def __gt__(self, other: object) -> bool:
55-
if isinstance(other, (int, float)):
56-
return round(self._value * self.__rr) > round(other * self.__rr)
57-
else:
58-
return NotImplemented
58+
match other:
59+
case int() | float():
60+
return round(self._value * self.__rr) > round(other * self.__rr)
61+
case _:
62+
return NotImplemented
5963

6064
def __le__(self, other: object) -> bool:
61-
if isinstance(other, (int, float)):
62-
return round(self._value * self.__rr) <= round(other * self.__rr)
63-
else:
64-
return NotImplemented
65+
match other:
66+
case int() | float():
67+
return round(self._value * self.__rr) <= round(other * self.__rr)
68+
case _:
69+
return NotImplemented
6570

6671
def __lt__(self, other: object) -> bool:
67-
if isinstance(other, (int, float)):
68-
return round(self._value * self.__rr) < round(other * self.__rr)
69-
else:
70-
return NotImplemented
72+
match other:
73+
case int() | float():
74+
return round(self._value * self.__rr) < round(other * self.__rr)
75+
case _:
76+
return NotImplemented
7177

7278
#
7379
# Arithmetics:
7480
#
7581

7682
def __add__(self, other: object) -> float:
77-
if isinstance(other, (int, float)):
78-
return (round(self._value * self.__rr) + round(other * self.__rr)) / self.__rr
79-
else:
80-
return NotImplemented
83+
match other:
84+
case int() | float():
85+
return (round(self._value * self.__rr) + round(other * self.__rr)) / self.__rr
86+
case _:
87+
return NotImplemented
8188

8289
def __sub__(self, other: object) -> float:
83-
if isinstance(other, (int, float)):
84-
return (round(self._value * self.__rr) - round(other * self.__rr)) / self.__rr
85-
else:
86-
return NotImplemented
90+
match other:
91+
case int() | float():
92+
return (round(self._value * self.__rr) - round(other * self.__rr)) / self.__rr
93+
case _:
94+
return NotImplemented
8795

8896
def __mul__(self, other: object) -> float:
89-
if isinstance(other, (int, float)):
90-
return (round(self._value * self.__rr) * round(other * self.__rr)) / (self.__rr ** 2)
91-
else:
92-
return NotImplemented
97+
match other:
98+
case int() | float():
99+
return (round(self._value * self.__rr) * round(other * self.__rr)) / (self.__rr ** 2)
100+
case _:
101+
return NotImplemented
93102

94103
def __floordiv__(self, other: object) -> float:
95-
if isinstance(other, (int, float)):
96-
return (round(self._value * self.__rr) // round(other * self.__rr))
97-
else:
98-
return NotImplemented
104+
match other:
105+
case int() | float():
106+
return (round(self._value * self.__rr) // round(other * self.__rr))
107+
case _:
108+
return NotImplemented
99109

100110
def __truediv__(self, other: object) -> float:
101-
if isinstance(other, (int, float)):
102-
return (round(self._value * self.__rr) / round(other * self.__rr))
103-
else:
104-
return NotImplemented
111+
match other:
112+
case int() | float():
113+
return (round(self._value * self.__rr) / round(other * self.__rr))
114+
case _:
115+
return NotImplemented
105116

106117
def __mod__(self, other: object) -> float:
107-
if isinstance(other, (int, float)):
108-
return (round(self._value * self.__rr) % round(other * self.__rr)) / (self.__rr)
109-
else:
110-
return NotImplemented
118+
match other:
119+
case int() | float():
120+
return (round(self._value * self.__rr) % round(other * self.__rr)) / (self.__rr)
121+
case _:
122+
return NotImplemented
111123

112124
# See the StdLib's comments on pow() on why it is Any, not float.
113125
def __pow__(self, power: float, modulo: None = None) -> Any:

looptime/patchers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ def patch_event_loop(
3030
**kwargs: Any,
3131
) -> loops.LoopTimeEventLoop:
3232
result: loops.LoopTimeEventLoop
33-
if isinstance(loop, loops.LoopTimeEventLoop):
34-
return loop
35-
else:
36-
new_class = make_event_loop_class(loop.__class__)
37-
loop.__class__ = new_class
38-
loop = cast(loops.LoopTimeEventLoop, loop)
39-
loop.setup_looptime(**kwargs)
40-
return loop
33+
match loop:
34+
case loops.LoopTimeEventLoop():
35+
return loop
36+
case _:
37+
new_class = make_event_loop_class(loop.__class__)
38+
loop.__class__ = new_class
39+
loop = cast(loops.LoopTimeEventLoop, loop)
40+
loop.setup_looptime(**kwargs)
41+
return loop
4142

4243

4344
def new_event_loop(**kwargs: Any) -> loops.LoopTimeEventLoop:

looptime/timeproxies.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ def __repr__(self) -> str:
2323
return f"<Loop time: {self._value}>"
2424

2525
def __matmul__(self, other: object) -> LoopTimeProxy:
26-
if isinstance(other, asyncio.AbstractEventLoop):
27-
return self.__class__(other)
28-
else:
29-
return NotImplemented
26+
match other:
27+
case asyncio.AbstractEventLoop():
28+
return self.__class__(other)
29+
case _:
30+
return NotImplemented
3031

3132
@property
3233
def _value(self) -> float:

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ classifiers = [
1818
"Framework :: aiohttp",
1919
"Programming Language :: Python",
2020
"Programming Language :: Python :: 3",
21-
"Programming Language :: Python :: 3.9",
2221
"Programming Language :: Python :: 3.10",
2322
"Programming Language :: Python :: 3.11",
2423
"Programming Language :: Python :: 3.12",
@@ -30,7 +29,7 @@ classifiers = [
3029
"Topic :: Software Development :: Libraries",
3130
"Typing :: Typed",
3231
]
33-
requires-python = ">=3.9"
32+
requires-python = ">=3.10"
3433
dependencies = [
3534
]
3635
dynamic = ["version"] # taken from git tags

0 commit comments

Comments
 (0)