astral-sh/ruff · error
expected ipy notebook
Error message
expected ipy notebook
What it means
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.
Source
Thrown at crates/ruff_linter/src/source_kind.rs:68
pub fn as_markdown(&self) -> Option<&str> {
match self {
SourceKind::Markdown(code) => Some(code),
SourceKind::Python { .. } => None,
SourceKind::IpyNotebook(_) => None,
}
}
pub fn expect_python(self) -> String {
match self {
SourceKind::Python { code, is_stub: _ } => code,
_ => panic!("expected python code"),
}
}
pub fn expect_ipy_notebook(self) -> Notebook {
match self {
SourceKind::IpyNotebook(notebook) => *notebook,
_ => panic!("expected ipy notebook"),
}
}
pub fn expect_markdown(self) -> String {
match self {
SourceKind::Markdown(code) => code,
_ => panic!("expected markdown text"),
}
}
pub fn py_source_type(&self) -> PySourceType {
match self {
Self::IpyNotebook(_) => PySourceType::Ipynb,
Self::Python { is_stub: true, .. } => PySourceType::Stub,
Self::Python { is_stub: false, .. } => PySourceType::Python,
Self::Markdown(_) => PySourceType::Python,
}
}View on GitHub (pinned to 26f38c119c)
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
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/ruff_linter/src/source_kind.rs:68 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/f491a104b13550df.
Report an issue: GitHub.