mirror of https://github.com/astral-sh/ruff
Change `quadratic-list-summation` docs to use `iadd` consistently (#10666)
Closes https://github.com/astral-sh/ruff/issues/10088.
This commit is contained in:
parent
3c48913473
commit
7c2e9f71ea
|
|
@ -24,10 +24,13 @@ use crate::importer::ImportRequest;
|
|||
/// quadratic complexity. The following methods are all linear in the number of
|
||||
/// lists:
|
||||
///
|
||||
/// - `functools.reduce(operator.iconcat, lists, [])`
|
||||
/// - `functools.reduce(operator.iadd, lists, [])`
|
||||
/// - `list(itertools.chain.from_iterable(lists))`
|
||||
/// - `[item for sublist in lists for item in sublist]`
|
||||
///
|
||||
/// When fixing relevant violations, Ruff defaults to the `functools.reduce`
|
||||
/// form, which outperforms the other methods in [microbenchmarks].
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
||||
|
|
@ -41,12 +44,14 @@ use crate::importer::ImportRequest;
|
|||
///
|
||||
///
|
||||
/// lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
||||
/// functools.reduce(operator.iconcat, lists, [])
|
||||
/// functools.reduce(operator.iadd, lists, [])
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [_How Not to Flatten a List of Lists in Python_](https://mathieularose.com/how-not-to-flatten-a-list-of-lists-in-python)
|
||||
/// - [_How do I make a flat list out of a list of lists?_](https://stackoverflow.com/questions/952914/how-do-i-make-a-flat-list-out-of-a-list-of-lists/953097#953097)
|
||||
///
|
||||
/// [microbenchmarks]: https://github.com/astral-sh/ruff/issues/5073#issuecomment-1591836349
|
||||
#[violation]
|
||||
pub struct QuadraticListSummation;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue