{"record":{"id":"56b3fa2ef7894603","repo":"astral-sh/ruff","slug":"could-not-determine-source-kind-for-file","errorCode":null,"errorMessage":"Could not determine source kind for file: {}","messagePattern":"Could not determine source kind for file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_dev/src/print_ast.rs","lineNumber":22,"sourceCode":"\nuse anyhow::Result;\n\nuse ruff_linter::source_kind::SourceKind;\nuse ruff_python_ast::{PySourceType, SourceType};\nuse ruff_python_parser::{ParseOptions, parse};\n\n#[derive(clap::Args)]\npub(crate) struct Args {\n    /// Python file for which to generate the AST.\n    #[arg(required = true)]\n    file: PathBuf,\n}\n\npub(crate) fn main(args: &Args) -> Result<()> {\n    let source_type = PySourceType::from(&args.file);\n    let source_kind = SourceKind::from_path(&args.file, SourceType::Python(source_type))?\n        .ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Could not determine source kind for file: {}\",\n                args.file.display()\n            )\n        })?;\n    let python_ast =\n        parse(source_kind.source_code(), ParseOptions::from(source_type))?.into_syntax();\n    println!(\"{python_ast:#?}\");\n    Ok(())\n}\n","sourceCodeStart":4,"sourceCodeEnd":32,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ruff_dev/src/print_ast.rs#L4-L32","documentation":"`cargo dev print-ast` loads the given file through SourceKind::from_path, which only recognizes `.py` and `.pyi` extensions; any other suffix (or no suffix) returns None and this error is raised.","triggerScenarios":"Running `cargo dev print-ast snippet.pyx`, `cargo dev print-ast script` (no extension), or any non-.py/.pyi path.","commonSituations":"Inspecting scratch files saved without extensions; .pyi-mislabeled stubs; test fixtures with custom suffixes such as .pyi.txt.","solutions":["Copy or rename the file to a `.py` (or `.pyi` for stubs) extension and rerun","If you need the AST of unusual inputs, pipe the source through a temporary .py file"],"exampleFix":"# before\ncargo dev print-ast snippet\n\n# after\ncp snippet /tmp/snippet.py && cargo dev print-ast /tmp/snippet.py","handlingStrategy":"validation","validationCode":"case \"$f\" in\n  *.py|*.pyi) cargo dev print-ast \"$f\" ;;\n  *) echo \"expected a .py or .pyi file: $f\" >&2; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Save scratch snippets with a .py extension before inspecting them","Remember .pyi selects stub parsing; use it deliberately for stub files"],"tags":["dev-tools","cli","python"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}