astral-sh/ruff · error
expected markdown text
Error message
expected markdown text
What it means
Panics in SourceKind::expect_markdown because the wrapped source is Python code or an ipynb notebook rather than Markdown text. Like the sibling expect_* methods, it asserts the caller already knows the variant; other kinds are a caller bug.
Source
Thrown at crates/ruff_linter/src/source_kind.rs:75
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,
}
}
#[must_use]
pub(crate) fn updated(&self, new_source: String, source_map: &SourceMap) -> Self {
match self {
SourceKind::IpyNotebook(notebook) => {
let mut cloned = notebook.clone();
cloned.update(source_map, new_source);View on GitHub (pinned to 26f38c119c)
Solutions
- Use as_markdown() or a match to confirm the variant first
- Only call expect_markdown on sources known to be Markdown
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/ruff_linter/src/source_kind.rs:75 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/4e6d072d68611dfa.
Report an issue: GitHub.