{"record":{"id":"953f12e0ed3f6f1c","repo":"astral-sh/ruff","slug":"expected-python-code","errorCode":null,"errorMessage":"expected python code","messagePattern":"expected python code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/source_kind.rs","lineNumber":61,"sourceCode":"        match self {\n            SourceKind::Python { code, .. } => Some(code),\n            SourceKind::Markdown(_) => None,\n            SourceKind::IpyNotebook(_) => None,\n        }\n    }\n\n    pub fn as_markdown(&self) -> Option<&str> {\n        match self {\n            SourceKind::Markdown(code) => Some(code),\n            SourceKind::Python { .. } => None,\n            SourceKind::IpyNotebook(_) => None,\n        }\n    }\n\n    pub fn expect_python(self) -> String {\n        match self {\n            SourceKind::Python { code, is_stub: _ } => code,\n            _ => panic!(\"expected python code\"),\n        }\n    }\n\n    pub fn expect_ipy_notebook(self) -> Notebook {\n        match self {\n            SourceKind::IpyNotebook(notebook) => *notebook,\n            _ => panic!(\"expected ipy notebook\"),\n        }\n    }\n\n    pub fn expect_markdown(self) -> String {\n        match self {\n            SourceKind::Markdown(code) => code,\n            _ => panic!(\"expected markdown text\"),\n        }\n    }\n\n    pub fn py_source_type(&self) -> PySourceType {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/source_kind.rs#L43-L79","documentation":"Panics in SourceKind::expect_python because the wrapped source is a Markdown document or an ipynb notebook rather than Python source. The method encodes an assumption that the caller already knows which variant it holds; using it on another kind is a programming error.","triggerScenarios":"Thrown at crates/ruff_linter/src/source_kind.rs:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check as_python() (or match on the variant) before calling expect_python","Pass the Python source through a code path that guarantees the Python variant"],"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"}