Skip to content

Commit 8288819

Browse files
cargo clippy
1 parent 38e34c5 commit 8288819

File tree

4 files changed

+71
-81
lines changed

4 files changed

+71
-81
lines changed

src/async_std.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! class="module-item stab portability"
66
//! style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"
77
//! ><code>unstable-streams</code></span>
8-
//! are only available when the `unstable-streams` Cargo feature is enabled:
8+
//! >are only available when the `unstable-streams` Cargo feature is enabled:
99
//!
1010
//! ```toml
1111
//! [dependencies.pyo3-asyncio-0-21]
@@ -71,7 +71,7 @@ impl Runtime for AsyncStdRuntime {
7171
AssertUnwindSafe(fut)
7272
.catch_unwind()
7373
.await
74-
.map_err(|e| AsyncStdJoinErr(e))
74+
.map_err(AsyncStdJoinErr)
7575
})
7676
}
7777
}
@@ -236,13 +236,13 @@ where
236236
/// via [`into_future`] (new behaviour in `v0.15`).
237237
///
238238
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
239-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
240-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
239+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
240+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
241241
/// >
242242
/// > As a workaround, you can get the `contextvars` from the current task locals using
243-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
244-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
245-
/// synchronous function, and restore the previous context when it returns or raises an exception.
243+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
244+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
245+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
246246
///
247247
/// # Arguments
248248
/// * `py` - PyO3 GIL guard
@@ -291,13 +291,13 @@ where
291291
/// via [`into_future`] (new behaviour in `v0.15`).
292292
///
293293
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
294-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
295-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
294+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
295+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
296296
/// >
297297
/// > As a workaround, you can get the `contextvars` from the current task locals using
298-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
299-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
300-
/// synchronous function, and restore the previous context when it returns or raises an exception.
298+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
299+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
300+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
301301
///
302302
/// # Arguments
303303
/// * `py` - The current PyO3 GIL guard
@@ -337,13 +337,13 @@ where
337337
/// via [`into_future`] (new behaviour in `v0.15`).
338338
///
339339
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
340-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
341-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
340+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
341+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
342342
/// >
343343
/// > As a workaround, you can get the `contextvars` from the current task locals using
344-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
345-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
346-
/// synchronous function, and restore the previous context when it returns or raises an exception.
344+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
345+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
346+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
347347
///
348348
/// # Arguments
349349
/// * `py` - PyO3 GIL guard
@@ -412,13 +412,13 @@ where
412412
/// via [`into_future`] (new behaviour in `v0.15`).
413413
///
414414
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
415-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
416-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
415+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
416+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
417417
/// >
418418
/// > As a workaround, you can get the `contextvars` from the current task locals using
419-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
420-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
421-
/// synchronous function, and restore the previous context when it returns or raises an exception.
419+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
420+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
421+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
422422
///
423423
/// # Arguments
424424
/// * `py` - The current PyO3 GIL guard
@@ -573,8 +573,8 @@ pub fn into_future(
573573
/// # fn main() {}
574574
/// ```
575575
#[cfg(feature = "unstable-streams")]
576-
pub fn into_stream_v1<'p>(
577-
gen: Bound<'p, PyAny>,
576+
pub fn into_stream_v1(
577+
gen: Bound<'_, PyAny>,
578578
) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static> {
579579
generic::into_stream_v1::<AsyncStdRuntime>(gen)
580580
}
@@ -633,9 +633,9 @@ pub fn into_stream_v1<'p>(
633633
/// # fn main() {}
634634
/// ```
635635
#[cfg(feature = "unstable-streams")]
636-
pub fn into_stream_with_locals_v1<'p>(
636+
pub fn into_stream_with_locals_v1(
637637
locals: TaskLocals,
638-
gen: Bound<'p, PyAny>,
638+
gen: Bound<'_, PyAny>,
639639
) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static> {
640640
generic::into_stream_with_locals_v1::<AsyncStdRuntime>(locals, gen)
641641
}
@@ -694,9 +694,9 @@ pub fn into_stream_with_locals_v1<'p>(
694694
/// # fn main() {}
695695
/// ```
696696
#[cfg(feature = "unstable-streams")]
697-
pub fn into_stream_with_locals_v2<'p>(
697+
pub fn into_stream_with_locals_v2(
698698
locals: TaskLocals,
699-
gen: Bound<'p, PyAny>,
699+
gen: Bound<'_, PyAny>,
700700
) -> PyResult<impl futures::Stream<Item = PyObject> + 'static> {
701701
generic::into_stream_with_locals_v2::<AsyncStdRuntime>(locals, gen)
702702
}
@@ -751,8 +751,8 @@ pub fn into_stream_with_locals_v2<'p>(
751751
/// # fn main() {}
752752
/// ```
753753
#[cfg(feature = "unstable-streams")]
754-
pub fn into_stream_v2<'p>(
755-
gen: Bound<'p, PyAny>,
754+
pub fn into_stream_v2(
755+
gen: Bound<'_, PyAny>,
756756
) -> PyResult<impl futures::Stream<Item = PyObject> + 'static> {
757757
generic::into_stream_v2::<AsyncStdRuntime>(gen)
758758
}

src/generic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,9 +1293,9 @@ where
12931293
/// ```
12941294
#[cfg(feature = "unstable-streams")]
12951295
#[allow(unused_must_use)] // False positive unused lint on `R::spawn`
1296-
pub fn into_stream_with_locals_v1<'p, R>(
1296+
pub fn into_stream_with_locals_v1<R>(
12971297
locals: TaskLocals,
1298-
gen: Bound<'p, PyAny>,
1298+
gen: Bound<'_, PyAny>,
12991299
) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static>
13001300
where
13011301
R: Runtime,
@@ -1437,8 +1437,8 @@ where
14371437
/// # }
14381438
/// ```
14391439
#[cfg(feature = "unstable-streams")]
1440-
pub fn into_stream_v1<'p, R>(
1441-
gen: Bound<'p, PyAny>,
1440+
pub fn into_stream_v1<R>(
1441+
gen: Bound<'_, PyAny>,
14421442
) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static>
14431443
where
14441444
R: Runtime + ContextExt,
@@ -1651,9 +1651,9 @@ async def forward(gen, sender):
16511651
/// # }
16521652
/// ```
16531653
#[cfg(feature = "unstable-streams")]
1654-
pub fn into_stream_with_locals_v2<'p, R>(
1654+
pub fn into_stream_with_locals_v2<R>(
16551655
locals: TaskLocals,
1656-
gen: Bound<'p, PyAny>,
1656+
gen: Bound<'_, PyAny>,
16571657
) -> PyResult<impl futures::Stream<Item = PyObject> + 'static>
16581658
where
16591659
R: Runtime + ContextExt,
@@ -1796,8 +1796,8 @@ where
17961796
/// # }
17971797
/// ```
17981798
#[cfg(feature = "unstable-streams")]
1799-
pub fn into_stream_v2<'p, R>(
1800-
gen: Bound<'p, PyAny>,
1799+
pub fn into_stream_v2<R>(
1800+
gen: Bound<'_, PyAny>,
18011801
) -> PyResult<impl futures::Stream<Item = PyObject> + 'static>
18021802
where
18031803
R: Runtime + ContextExt,

src/testing.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,11 @@ use pyo3::prelude::*;
189189
///
190190
/// These args are meant to mirror the default test harness's args.
191191
/// > Currently only `--filter` is supported.
192+
#[derive(Default)]
192193
pub struct Args {
193194
filter: Option<String>,
194195
}
195196

196-
impl Default for Args {
197-
fn default() -> Self {
198-
Self { filter: None }
199-
}
200-
}
201-
202197
/// Parse the test args from the command line
203198
///
204199
/// This should be called at the start of your test harness to give the CLI some
@@ -240,9 +235,7 @@ pub fn parse_args() -> Args {
240235
.get_matches();
241236

242237
Args {
243-
filter: matches
244-
.get_one::<String>("TESTNAME")
245-
.map(|name| name.clone()),
238+
filter: matches.get_one::<String>("TESTNAME").cloned(),
246239
}
247240
}
248241

@@ -315,11 +308,7 @@ pub async fn test_harness(tests: Vec<Test>, args: Args) -> PyResult<()> {
315308
pub async fn main() -> PyResult<()> {
316309
let args = parse_args();
317310

318-
test_harness(
319-
inventory::iter::<Test>().map(|test| test.clone()).collect(),
320-
args,
321-
)
322-
.await
311+
test_harness(inventory::iter::<Test>().cloned().collect(), args).await
323312
}
324313

325314
#[cfg(test)]

src/tokio.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! class="module-item stab portability"
66
//! style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"
77
//! ><code>unstable-streams</code></span>
8-
//! are only available when the `unstable-streams` Cargo feature is enabled:
8+
//! >are only available when the `unstable-streams` Cargo feature is enabled:
99
//!
1010
//! ```toml
1111
//! [dependencies.pyo3-asyncio-0-21]
@@ -176,6 +176,7 @@ pub fn init(builder: Builder) {
176176
/// Initialize the Tokio runtime with a custom Tokio runtime
177177
///
178178
/// Returns Ok(()) if success and Err(()) if it had been inited.
179+
#[allow(clippy::result_unit_err)]
179180
pub fn init_with_runtime(runtime: &'static Runtime) -> Result<(), ()> {
180181
TOKIO_RUNTIME
181182
.set(Pyo3Runtime::Borrowed(runtime))
@@ -278,13 +279,13 @@ where
278279
/// via [`into_future`] (new behaviour in `v0.15`).
279280
///
280281
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
281-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
282-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
282+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
283+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
283284
/// >
284285
/// > As a workaround, you can get the `contextvars` from the current task locals using
285-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
286-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
287-
/// synchronous function, and restore the previous context when it returns or raises an exception.
286+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
287+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
288+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
288289
///
289290
/// # Arguments
290291
/// * `py` - PyO3 GIL guard
@@ -333,13 +334,13 @@ where
333334
/// via [`into_future`] (new behaviour in `v0.15`).
334335
///
335336
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
336-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
337-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
337+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
338+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
338339
/// >
339340
/// > As a workaround, you can get the `contextvars` from the current task locals using
340-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
341-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
342-
/// synchronous function, and restore the previous context when it returns or raises an exception.
341+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
342+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
343+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
343344
///
344345
/// # Arguments
345346
/// * `py` - The current PyO3 GIL guard
@@ -379,13 +380,13 @@ where
379380
/// via [`into_future`] (new behaviour in `v0.15`).
380381
///
381382
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
382-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
383-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
383+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
384+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
384385
/// >
385386
/// > As a workaround, you can get the `contextvars` from the current task locals using
386-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
387-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
388-
/// synchronous function, and restore the previous context when it returns or raises an exception.
387+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
388+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
389+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
389390
///
390391
/// # Arguments
391392
/// * `py` - PyO3 GIL guard
@@ -470,13 +471,13 @@ where
470471
/// via [`into_future`] (new behaviour in `v0.15`).
471472
///
472473
/// > Although `contextvars` are preserved for async Python functions, synchronous functions will
473-
/// unfortunately fail to resolve them when called within the Rust future. This is because the
474-
/// function is being called from a Rust thread, not inside an actual Python coroutine context.
474+
/// > unfortunately fail to resolve them when called within the Rust future. This is because the
475+
/// > function is being called from a Rust thread, not inside an actual Python coroutine context.
475476
/// >
476477
/// > As a workaround, you can get the `contextvars` from the current task locals using
477-
/// [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
478-
/// synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
479-
/// synchronous function, and restore the previous context when it returns or raises an exception.
478+
/// > [`get_current_locals`] and [`TaskLocals::context`](`crate::TaskLocals::context`), then wrap your
479+
/// > synchronous function in a call to `contextvars.Context.run`. This will set the context, call the
480+
/// > synchronous function, and restore the previous context when it returns or raises an exception.
480481
///
481482
/// # Arguments
482483
/// * `py` - The current PyO3 GIL guard
@@ -650,9 +651,9 @@ pub fn into_future(
650651
/// # fn main() {}
651652
/// ```
652653
#[cfg(feature = "unstable-streams")]
653-
pub fn into_stream_with_locals_v1<'p>(
654+
pub fn into_stream_with_locals_v1(
654655
locals: TaskLocals,
655-
gen: Bound<'p, PyAny>,
656+
gen: Bound<'_, PyAny>,
656657
) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static> {
657658
generic::into_stream_with_locals_v1::<TokioRuntime>(locals, gen)
658659
}
@@ -707,8 +708,8 @@ pub fn into_stream_with_locals_v1<'p>(
707708
/// # fn main() {}
708709
/// ```
709710
#[cfg(feature = "unstable-streams")]
710-
pub fn into_stream_v1<'p>(
711-
gen: Bound<'p, PyAny>,
711+
pub fn into_stream_v1(
712+
gen: Bound<'_, PyAny>,
712713
) -> PyResult<impl futures::Stream<Item = PyResult<PyObject>> + 'static> {
713714
generic::into_stream_v1::<TokioRuntime>(gen)
714715
}
@@ -767,9 +768,9 @@ pub fn into_stream_v1<'p>(
767768
/// # fn main() {}
768769
/// ```
769770
#[cfg(feature = "unstable-streams")]
770-
pub fn into_stream_with_locals_v2<'p>(
771+
pub fn into_stream_with_locals_v2(
771772
locals: TaskLocals,
772-
gen: Bound<'p, PyAny>,
773+
gen: Bound<'_, PyAny>,
773774
) -> PyResult<impl futures::Stream<Item = PyObject> + 'static> {
774775
generic::into_stream_with_locals_v2::<TokioRuntime>(locals, gen)
775776
}
@@ -824,8 +825,8 @@ pub fn into_stream_with_locals_v2<'p>(
824825
/// # fn main() {}
825826
/// ```
826827
#[cfg(feature = "unstable-streams")]
827-
pub fn into_stream_v2<'p>(
828-
gen: Bound<'p, PyAny>,
828+
pub fn into_stream_v2(
829+
gen: Bound<'_, PyAny>,
829830
) -> PyResult<impl futures::Stream<Item = PyObject> + 'static> {
830831
generic::into_stream_v2::<TokioRuntime>(gen)
831832
}

0 commit comments

Comments
 (0)