Skip to content

Commit 4889426

Browse files
committed
Add clippy lint to CI / fix clippy lints
1 parent b94d361 commit 4889426

File tree

10 files changed

+40
-34
lines changed

10 files changed

+40
-34
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
python: "3.12"
2020
docsTarget: true
2121
cloudTestTarget: true
22+
clippyLinter: true
2223
- os: ubuntu-latest
2324
python: "3.8"
2425
protoCheckTarget: true
@@ -58,6 +59,8 @@ jobs:
5859
# https://github.com/python-poetry/poetry/pull/7694 are fixed
5960
- run: python -m pip install --upgrade wheel "poetry==1.3.2" poethepoet
6061
- run: poetry install --no-root --all-extras
62+
- run: poe bridge-lint
63+
if: ${{ matrix.clippyLinter }}
6164
- run: poe lint
6265
- run: poe build-develop
6366
- run: mkdir junit-xml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ temporalio/bridge/temporal_sdk_bridge*
77
/tests/helpers/golangserver/golangserver
88
/tests/helpers/golangworker/golangworker
99
/.idea
10+
/sdk-python.iml

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ lint = [
8181
{cmd = "pyright"},
8282
{ref = "lint-docs"},
8383
]
84+
bridge-lint = { cmd = "cargo clippy -- -D warnings", cwd = "temporalio/bridge" }
8485
# TODO(cretz): Why does pydocstyle complain about @overload missing docs after
8586
# https://github.com/PyCQA/pydocstyle/pull/511?
8687
lint-docs = "pydocstyle --ignore-decorators=overload"

temporalio/bridge/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ impl TryFrom<ClientConfig> for ClientOptions {
502502
if let Some(tls_config) = opts.tls_config {
503503
gateway_opts.tls_cfg(tls_config.try_into()?);
504504
}
505-
return gateway_opts
505+
gateway_opts
506506
.build()
507-
.map_err(|err| PyValueError::new_err(format!("Invalid client config: {}", err)));
507+
.map_err(|err| PyValueError::new_err(format!("Invalid client config: {}", err)))
508508
}
509509
}
510510

temporalio/bridge/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ fn connect_client<'a>(
6363
runtime_ref: &runtime::RuntimeRef,
6464
config: client::ClientConfig,
6565
) -> PyResult<&'a PyAny> {
66-
client::connect_client(py, &runtime_ref, config)
66+
client::connect_client(py, runtime_ref, config)
6767
}
6868

6969
#[pyfunction]
7070
fn new_metric_meter(runtime_ref: &runtime::RuntimeRef) -> Option<metric::MetricMeterRef> {
71-
metric::new_metric_meter(&runtime_ref)
71+
metric::new_metric_meter(runtime_ref)
7272
}
7373

7474
#[pyfunction]
@@ -77,7 +77,7 @@ fn init_runtime(telemetry_config: runtime::TelemetryConfig) -> PyResult<runtime:
7777
}
7878

7979
#[pyfunction]
80-
fn raise_in_thread<'a>(py: Python<'a>, thread_id: std::os::raw::c_long, exc: &PyAny) -> bool {
80+
fn raise_in_thread(py: Python, thread_id: std::os::raw::c_long, exc: &PyAny) -> bool {
8181
runtime::raise_in_thread(py, thread_id, exc)
8282
}
8383

@@ -87,7 +87,7 @@ fn start_dev_server<'a>(
8787
runtime_ref: &runtime::RuntimeRef,
8888
config: testing::DevServerConfig,
8989
) -> PyResult<&'a PyAny> {
90-
testing::start_dev_server(py, &runtime_ref, config)
90+
testing::start_dev_server(py, runtime_ref, config)
9191
}
9292

9393
#[pyfunction]
@@ -96,7 +96,7 @@ fn start_test_server<'a>(
9696
runtime_ref: &runtime::RuntimeRef,
9797
config: testing::TestServerConfig,
9898
) -> PyResult<&'a PyAny> {
99-
testing::start_test_server(py, &runtime_ref, config)
99+
testing::start_test_server(py, runtime_ref, config)
100100
}
101101

102102
#[pyfunction]
@@ -105,7 +105,7 @@ fn new_worker(
105105
client: &client::ClientRef,
106106
config: worker::WorkerConfig,
107107
) -> PyResult<worker::WorkerRef> {
108-
worker::new_worker(&runtime_ref, &client, config)
108+
worker::new_worker(runtime_ref, client, config)
109109
}
110110

111111
#[pyfunction]
@@ -114,5 +114,5 @@ fn new_replay_worker<'a>(
114114
runtime_ref: &runtime::RuntimeRef,
115115
config: worker::WorkerConfig,
116116
) -> PyResult<&'a PyTuple> {
117-
worker::new_replay_worker(py, &runtime_ref, config)
117+
worker::new_replay_worker(py, runtime_ref, config)
118118
}

temporalio/bridge/src/metric.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ fn build_metric_parameters(
221221

222222
#[pymethods]
223223
impl MetricAttributesRef {
224-
fn with_additional_attributes<'p>(
224+
fn with_additional_attributes(
225225
&self,
226-
py: Python<'p>,
226+
py: Python,
227227
meter: &MetricMeterRef,
228228
new_attrs: HashMap<String, PyObject>,
229229
) -> PyResult<Self> {
@@ -240,8 +240,8 @@ impl MetricAttributesRef {
240240
}
241241
}
242242

243-
fn metric_key_value_from_py<'p>(
244-
py: Python<'p>,
243+
fn metric_key_value_from_py(
244+
py: Python,
245245
k: String,
246246
obj: PyObject,
247247
) -> PyResult<metrics::MetricKeyValue> {
@@ -317,8 +317,8 @@ impl CustomMetricAttributes for BufferedMetricAttributes {
317317
}
318318
}
319319

320-
pub fn convert_metric_events<'p>(
321-
py: Python<'p>,
320+
pub fn convert_metric_events(
321+
py: Python,
322322
events: Vec<MetricEvent<BufferedMetricRef>>,
323323
durations_as_seconds: bool,
324324
) -> Vec<BufferedMetricUpdate> {
@@ -328,8 +328,8 @@ pub fn convert_metric_events<'p>(
328328
.collect()
329329
}
330330

331-
fn convert_metric_event<'p>(
332-
py: Python<'p>,
331+
fn convert_metric_event(
332+
py: Python,
333333
event: MetricEvent<BufferedMetricRef>,
334334
durations_as_seconds: bool,
335335
) -> Option<BufferedMetricUpdate> {

temporalio/bridge/src/runtime.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ pub fn init_runtime(telemetry_config: TelemetryConfig) -> PyResult<RuntimeRef> {
122122
// Event loop is assumed to be running at this point
123123
let locals = pyo3_asyncio::TaskLocals::with_running_loop(py)?.copy_context(py)?;
124124
PyResult::Ok(locals)
125-
})
126-
.expect("Works");
125+
})?;
127126

128127
// Create core runtime which starts tokio multi-thread runtime
129128
let mut core = CoreRuntime::new(
@@ -136,11 +135,12 @@ pub fn init_runtime(telemetry_config: TelemetryConfig) -> PyResult<RuntimeRef> {
136135
// Set task locals for each thread
137136
Python::with_gil(|_| {
138137
THREAD_TASK_LOCAL.with(|r| {
139-
std::cell::OnceCell::set(r, task_locals.clone()).expect("NOT ALREADY SET");
138+
std::cell::OnceCell::set(r, task_locals.clone())
139+
.expect("TaskLocals are only set once");
140140
});
141141
PyResult::Ok(())
142142
})
143-
.expect("Setting event loop works");
143+
.expect("Setting per-thread python TaskLocals must work");
144144
}),
145145
},
146146
)
@@ -197,7 +197,7 @@ pub fn init_runtime(telemetry_config: TelemetryConfig) -> PyResult<RuntimeRef> {
197197
})
198198
}
199199

200-
pub fn raise_in_thread<'a>(_py: Python<'a>, thread_id: std::os::raw::c_long, exc: &PyAny) -> bool {
200+
pub fn raise_in_thread(_py: Python, thread_id: std::os::raw::c_long, exc: &PyAny) -> bool {
201201
unsafe { pyo3::ffi::PyThreadState_SetAsyncExc(thread_id, exc.as_ptr()) == 1 }
202202
}
203203

@@ -223,9 +223,9 @@ impl Drop for Runtime {
223223

224224
#[pymethods]
225225
impl RuntimeRef {
226-
fn retrieve_buffered_metrics<'p>(
226+
fn retrieve_buffered_metrics(
227227
&self,
228-
py: Python<'p>,
228+
py: Python,
229229
durations_as_seconds: bool,
230230
) -> Vec<BufferedMetricUpdate> {
231231
convert_metric_events(
@@ -316,7 +316,7 @@ impl TryFrom<MetricsConfig> for Arc<dyn CoreMeter> {
316316

317317
fn try_from(conf: MetricsConfig) -> PyResult<Self> {
318318
if let Some(otel_conf) = conf.opentelemetry {
319-
if !conf.prometheus.is_none() {
319+
if conf.prometheus.is_some() {
320320
return Err(PyValueError::new_err(
321321
"Cannot have OpenTelemetry and Prometheus metrics",
322322
));
@@ -391,7 +391,7 @@ tokio::task_local! {
391391

392392
thread_local! {
393393
pub(crate) static THREAD_TASK_LOCAL: std::cell::OnceCell<pyo3_asyncio::TaskLocals> =
394-
std::cell::OnceCell::new();
394+
const { std::cell::OnceCell::new() };
395395
}
396396

397397
impl pyo3_asyncio::generic::Runtime for TokioRuntime {
@@ -421,9 +421,8 @@ impl pyo3_asyncio::generic::ContextExt for TokioRuntime {
421421
}
422422

423423
fn get_task_locals() -> Option<pyo3_asyncio::TaskLocals> {
424-
match TASK_LOCALS.try_with(|c| c.get().map(|locals| locals.clone())) {
425-
Ok(locals) => locals,
426-
Err(_) => None,
427-
}
424+
TASK_LOCALS
425+
.try_with(|c| c.get().cloned())
426+
.unwrap_or_default()
428427
}
429428
}

temporalio/bridge/worker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import temporalio.bridge.temporal_sdk_bridge
3636
import temporalio.converter
3737
import temporalio.exceptions
38+
from temporalio.bridge.temporal_sdk_bridge import (
39+
CustomSlotSupplier as BridgeCustomSlotSupplier,
40+
)
3841
from temporalio.bridge.temporal_sdk_bridge import PollShutdownError
3942

4043

temporalio/worker/_tuning.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from typing_extensions import TypeAlias
99

10-
import temporalio.bridge.temporal_sdk_bridge
1110
import temporalio.bridge.worker
1211
from temporalio.bridge.worker import (
1312
ActivitySlotInfo,
13+
BridgeCustomSlotSupplier,
1414
CustomSlotSupplier,
1515
LocalActivitySlotInfo,
1616
SlotInfo,
@@ -160,9 +160,7 @@ def _to_bridge_slot_supplier(
160160
),
161161
)
162162
elif isinstance(slot_supplier, CustomSlotSupplier):
163-
return temporalio.bridge.temporal_sdk_bridge.CustomSlotSupplier(
164-
_ErrorLoggingSlotSupplier(slot_supplier)
165-
)
163+
return BridgeCustomSlotSupplier(_ErrorLoggingSlotSupplier(slot_supplier))
166164
else:
167165
raise TypeError(f"Unknown slot supplier type: {slot_supplier}")
168166

tests/worker/test_worker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ def release_slot(self, ctx: SlotReleaseContext) -> None:
509509
) as _w:
510510
await asyncio.sleep(1)
511511

512+
512513
def create_worker(
513514
client: Client,
514515
on_fatal_error: Optional[Callable[[BaseException], Awaitable[None]]] = None,

0 commit comments

Comments
 (0)