{"record":{"id":"71ecc7553c5a1753","repo":"astral-sh/ruff","slug":"could-not-determine-source-kind-for-file-71ecc7","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_tokens.rs","lineNumber":22,"sourceCode":"\nuse anyhow::Result;\n\nuse ruff_linter::linter::parse_unchecked_source;\nuse ruff_linter::source_kind::SourceKind;\nuse ruff_python_ast::{PySourceType, PythonVersion, SourceType};\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 parsed = parse_unchecked_source(&source_kind, source_type, PythonVersion::default());\n    for token in parsed.tokens() {\n        println!(\"{token:#?}\");\n    }\n    Ok(())\n}\n","sourceCodeStart":4,"sourceCodeEnd":33,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ruff_dev/src/print_tokens.rs#L4-L33","documentation":"`cargo dev print-tokens` 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-tokens lexer.txt` or any path that does not end in .py/.pyi.","commonSituations":"Tokenizing scratch files without extensions or with renamed suffixes; fixtures saved as .python or .src.","solutions":["Copy or rename the file to `.py` (or `.pyi`) and rerun","Feed the content via a temporary .py file when the original name must stay unchanged"],"exampleFix":"# before\ncargo dev print-tokens tokens\n\n# after\ncp tokens /tmp/tokens.py && cargo dev print-tokens /tmp/tokens.py","handlingStrategy":"validation","validationCode":"case \"$f\" in\n  *.py|*.pyi) cargo dev print-tokens \"$f\" ;;\n  *) echo \"expected a .py or .pyi file: $f\" >&2; exit 1 ;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep token-inspection inputs as .py files","For extensionless fixtures, copy to /tmp/<name>.py first"],"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"}