Skip to content

Commit efe6997

Browse files
authored
Make typing on UniqueOpts.by_state true JobState enums instead of strings (#32)
Make the typing on `UniqueOpts.by_state` strong by making it a list of `JobState` enums instead of a list of strings. Change usages in the test suite over to enums instead of strings.
1 parent 622a659 commit efe6997

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `UniqueOpts.by_state` now has the stronger type of `list[JobState]` (the enum) instead of `list[str]`. [PR #32](https://github.com/riverqueue/riverqueue-python/pull/32).
13+
1014
## [0.6.1] - 2024-07-06
1115

1216
### Fixed

src/riverqueue/client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Tuple,
99
List,
1010
Callable,
11+
cast,
1112
runtime_checkable,
1213
)
1314

@@ -644,7 +645,7 @@ def _build_unique_get_params_and_lock_key(
644645
if unique_opts.by_state:
645646
any_unique_opts = True
646647
get_params.by_state = True
647-
get_params.state = unique_opts.by_state
648+
get_params.state = cast(list[str], unique_opts.by_state)
648649
lock_str += f"&state={','.join(unique_opts.by_state)}"
649650
else:
650651
get_params.state = UNIQUE_STATES_DEFAULT

src/riverqueue/insert_opts.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from datetime import datetime
33
from typing import Any, Literal, Optional
44

5+
from riverqueue.job import JobState
6+
57

68
@dataclass
79
class InsertOpts:
@@ -119,7 +121,7 @@ class UniqueOpts:
119121
enabled, uniqueness will be enforced for a kind across all queues.
120122
"""
121123

122-
by_state: Optional[list[str]] = None
124+
by_state: Optional[list[JobState]] = None
123125
"""
124126
Indicates that uniqueness should be enforced across any of the states in
125127
the given set. For example, if the given states were `(scheduled,

tests/driver/riversqlalchemy/sqlalchemy_driver_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def test_insert_with_unique_opts_by_queue(self, client, simple_args):
180180
@pytest.mark.asyncio
181181
async def test_insert_with_unique_opts_by_state(self, client, simple_args):
182182
insert_opts = InsertOpts(
183-
unique_opts=UniqueOpts(by_state=["available", "running"])
183+
unique_opts=UniqueOpts(by_state=[JobState.AVAILABLE, JobState.RUNNING])
184184
)
185185
insert_res = await client.insert(simple_args, insert_opts=insert_opts)
186186
assert insert_res.job
@@ -299,7 +299,7 @@ def test_insert_with_unique_opts_by_queue(self, client, simple_args):
299299

300300
def test_insert_with_unique_opts_by_state(self, client, simple_args):
301301
insert_opts = InsertOpts(
302-
unique_opts=UniqueOpts(by_state=["available", "running"])
302+
unique_opts=UniqueOpts(by_state=[JobState.AVAILABLE, JobState.RUNNING])
303303
)
304304
insert_res = client.insert(simple_args, insert_opts=insert_opts)
305305
assert insert_res.job

0 commit comments

Comments
 (0)