{"record":{"id":"05fe19337553de47","repo":"astral-sh/ruff","slug":"value-cannot-be-converted-to-emptystringcmpop","errorCode":null,"errorMessage":"{value:?} cannot be converted to EmptyStringCmpOp","messagePattern":"(.+?) cannot be converted to EmptyStringCmpOp","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs","lineNumber":132,"sourceCode":"\n#[derive(Debug, PartialEq, Eq, Copy, Clone)]\nenum EmptyStringCmpOp {\n    Is,\n    IsNot,\n    Eq,\n    NotEq,\n}\n\nimpl TryFrom<&CmpOp> for EmptyStringCmpOp {\n    type Error = anyhow::Error;\n\n    fn try_from(value: &CmpOp) -> Result<Self, Self::Error> {\n        match value {\n            CmpOp::Is => Ok(Self::Is),\n            CmpOp::IsNot => Ok(Self::IsNot),\n            CmpOp::Eq => Ok(Self::Eq),\n            CmpOp::NotEq => Ok(Self::NotEq),\n            _ => bail!(\"{value:?} cannot be converted to EmptyStringCmpOp\"),\n        }\n    }\n}\n\nimpl EmptyStringCmpOp {\n    fn into_unary(self) -> &'static str {\n        match self {\n            Self::Is | Self::Eq => \"not \",\n            Self::IsNot | Self::NotEq => \"\",\n        }\n    }\n}\n\nimpl std::fmt::Display for EmptyStringCmpOp {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        let repr = match self {\n            Self::Is => \"is\",\n            Self::IsNot => \"is not\",","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/astral-sh/ruff/blob/15f3fe6b15a5f00172f34b0f542f8ea277f5a586/crates/ruff_linter/src/rules/pylint/rules/compare_to_empty_string.rs#L114-L150","documentation":"Pylint's PRM-style rule checking comparisons against empty strings ('' or \"\") only understands a subset of comparison operators (is, is not, ==, !=). The `TryFrom<&CmpOp>` conversion bails for any other operator, indicating the rule's checker reached a comparison with an unsupported operator — a diagnostic/fix invariant violation.","triggerScenarios":"`try_from` was called with a `CmpOp` other than Is/IsNot/Eq/NotEq (e.g. `<`, `>=`, `in`) during PLC0202/E710-ish empty-string comparison analysis.","commonSituations":"Effectively unreachable with stock Ruff since the rule only matches supported operators; appears with modified builds or AST-level changes.","solutions":["Update Ruff to the latest release","Rewrite the comparison to use `==`/`!=` against '' if the diagnostic is intended","File an issue with the offending comparison if reproducible"],"exampleFix":"# before\nif s == '':\n    pass\n# after\nif not s:\n    pass","handlingStrategy":"validation","validationCode":"# Only ==/!=/is/is not comparisons against '' are supported by the rule:\nif value == '':\n    ...  # flagged; rewrite as `if not value:`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use truthiness (`if not s:` / `if s:`) instead of comparing to ''","Restrict comparisons against literals to ==/!=/is/is not","Keep Ruff updated"],"tags":["ruff","pylint","autofix","comparison"],"backgroundTag":"autofix-failed-to-apply","analyzedSha":"15f3fe6b15a5f00172f34b0f542f8ea277f5a586","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}