{"record":{"id":"a15442c44fcae4ee","repo":"astral-sh/ruff","slug":"we-shouldn-t-be-attempting-an-autofix-if-a-sequenc","errorCode":null,"errorMessage":"We shouldn't be attempting an autofix if a sequence has < 2 elements; a sequence with 1 or 0 elements cannot be unsorted.","messagePattern":"We shouldn't be attempting an autofix if a sequence has < 2 elements; a sequence with 1 or 0 elements cannot be unsorted\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs","lineNumber":448,"sourceCode":"        })\n    }\n\n    /// Sort a multiline sequence of literal strings\n    /// that is known to be unsorted.\n    ///\n    /// This function panics if it is called and `self.items`\n    /// has length < 2. It's redundant to call this method in this case,\n    /// since lists with < 2 items cannot be unsorted,\n    /// so this is a logic error.\n    pub(super) fn into_sorted_source_code(\n        mut self,\n        sorting_style: SortingStyle,\n        locator: &Locator,\n        stylist: &Stylist,\n    ) -> String {\n        let (first_item_start, last_item_end) = match self.items.as_slice() {\n            [first_item, .., last_item] => (first_item.start(), last_item.end()),\n            _ => panic!(\n                \"We shouldn't be attempting an autofix if a sequence has < 2 elements;\n                a sequence with 1 or 0 elements cannot be unsorted.\"\n            ),\n        };\n\n        // As well as the \"items\" in a multiline string sequence,\n        // there is also a \"prelude\" and a \"postlude\":\n        //  - Prelude == the region of source code from the opening parenthesis,\n        //    up to the start of the first item in `__all__`/`__slots__`/etc.\n        //  - Postlude == the region of source code from the end of the last\n        //    item in `__all__`/`__slots__`/etc. up to and including the closing\n        //    parenthesis.\n        //\n        // For example:\n        //\n        // ```python\n        // __all__ = [  # comment0\n        //   # comment1","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs#L430-L466","documentation":"A deliberate panic in into_sorted_source_code: the sorter was asked to sort a literal sequence with fewer than two items. Sequences of length 0 or 1 cannot be unsorted, so the caller violated the method's documented precondition — a logic error in the rule that detected the sequence as unsorted.","triggerScenarios":"Thrown at crates/ruff_linter/src/rules/ruff/rules/sequence_sorting.rs:448 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the caller to only request a fix when the sequence has at least two items","Return an empty/unchanged result instead of panicking for short sequences"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}