{"record":{"id":"f491a104b13550df","repo":"astral-sh/ruff","slug":"expected-ipy-notebook","errorCode":null,"errorMessage":"expected ipy notebook","messagePattern":"expected ipy notebook","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/source_kind.rs","lineNumber":68,"sourceCode":"    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 {\n        match self {\n            Self::IpyNotebook(_) => PySourceType::Ipynb,\n            Self::Python { is_stub: true, .. } => PySourceType::Stub,\n            Self::Python { is_stub: false, .. } => PySourceType::Python,\n            Self::Markdown(_) => PySourceType::Python,\n        }\n    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/source_kind.rs#L50-L86","documentation":"Panics in SourceKind::expect_ipy_notebook because the wrapped source is Python code or Markdown, not a notebook. The method is an assertion that the caller has already verified the variant, so misuse indicates the caller lost track of the file kind.","triggerScenarios":"Thrown at crates/ruff_linter/src/source_kind.rs:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Match on SourceKind or check the notebook variant before calling expect_ipy_notebook","Route notebook handling only from paths that produce the IpyNotebook 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-14T05:17:10.506Z"}