{"record":{"id":"4f2338be7cd50122","repo":"astral-sh/uv","slug":"cannot-use-as-an-exclude-file","errorCode":null,"errorMessage":"Cannot use `{}` as an exclude file","messagePattern":"Cannot use `(.+?)` as an exclude file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/uv-requirements/src/specification.rs","lineNumber":454,"sourceCode":"            } else {\n                None\n            }\n        }) {\n            return Err(anyhow::anyhow!(\n                \"Cannot use `{}` as an override file\",\n                pylock_toml.user_display()\n            ));\n        }\n\n        // Disallow `pylock.toml` files as excludes.\n        if let Some(pylock_toml) = excludes.iter().find_map(|source| {\n            if let RequirementsSource::PylockToml(path) = source {\n                Some(path)\n            } else {\n                None\n            }\n        }) {\n            return Err(anyhow::anyhow!(\n                \"Cannot use `{}` as an exclude file\",\n                pylock_toml.user_display()\n            ));\n        }\n\n        // If we have a `pylock.toml`, don't allow additional requirements, constraints, or\n        // overrides.\n        if let Some(pylock_toml) = requirements.iter().find_map(|source| {\n            if let RequirementsSource::PylockToml(path) = source {\n                Some(path)\n            } else {\n                None\n            }\n        }) {\n            if requirements\n                .iter()\n                .any(|source| !matches!(source, RequirementsSource::PylockToml(..)))\n            {","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/astral-sh/uv/blob/f1a42680ff5272232d65748acf338b19778dde24/crates/uv-requirements/src/specification.rs#L436-L472","documentation":"Thrown in RequirementsSpecification::from_sources (crates/uv-requirements/src/specification.rs:454) when the excludes list contains a RequirementsSource::PylockToml variant. Exclusion sources mark packages to drop from resolution; a PEP 751 lock file cannot serve that role, so uv refuses it while assembling the combined specification.","triggerScenarios":"Programmatic from_sources invocation with a PylockToml source in the excludes Vec; a CLI flow that resolved an exclusion path to a pylock source before this constructor; only the first offending file is reported.","commonSituations":"Tooling that passes lock files into every source slot uniformly; misconfigured exclude lists built from directory globs.","solutions":["Remove the pylock.toml from the excludes list","Express exclusions as a requirements.txt-style file listing package names to exclude","If you meant to constrain resolution to the lock, see errors 53/57 for the supported patterns"],"exampleFix":"# before (programmatic)\nexcludes: vec![RequirementsSource::PylockToml(lock.into())],\n// after\nexcludes: vec![RequirementsSource::RequirementsTxt(excl.into())],","handlingStrategy":"validation","validationCode":"let bad = excludes.iter().any(|s| matches!(s, RequirementsSource::PylockToml(_)));\nif bad {\n    return Err(anyhow::anyhow!(\"refusing to assemble spec: pylock.toml is not an exclude source\"));\n}","typeGuard":"fn is_pylock_source(s: &RequirementsSource) -> bool {\n    matches!(s, RequirementsSource::PylockToml(_))\n}","tryCatchPattern":"match RequirementsSpecification::from_sources(/* .. */).await {\n    Err(err) if err.to_string().contains(\"as an exclude file\") => {\n        // drop the pylock entry and reassemble\n    }\n    spec => spec?,\n}","preventionTips":["Express excludes as plain package-name lists in .txt files","Validate every source slot by role before calling from_sources","Never reuse one path across constraints/overrides/excludes lists"],"tags":["uv","excludes","pylock-toml","api-misuse"],"backgroundTag":null,"analyzedSha":"f1a42680ff5272232d65748acf338b19778dde24","analyzedAt":"2026-08-16T04:51:47.599Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}