From 6660b11422d299e732d79cc6f5347da3ca300aae Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Fri, 11 Jul 2025 14:07:34 -0700 Subject: [PATCH] [`pyupgrade`] Make example error out-of-the-box (`UP023`) (#19291) ## Summary Part of #18972 This PR makes [deprecated-c-element-tree (UP023)](https://docs.astral.sh/ruff/rules/deprecated-c-element-tree/#deprecated-c-element-tree-up023)'s example error out-of-the-box. I have no clue why the `import xml.etree.cElementTree` and `from xml.etree import cElementTree` cases are specifically carved out if they do not have an `as ...`, but the tests explicitly call this out, and that's how it is in `pyupgrade`'s source as well. https://github.com/astral-sh/ruff/blob/b5c5f710fc12b5c512a2e5351684b8ffdf33761f/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP023.py#L23-L31 [Old example](https://play.ruff.rs/632b8ce1-393d-45e5-9504-5444ae71a0d8) ```py from xml.etree import cElementTree ``` [New example](https://play.ruff.rs/fef4d378-8c54-41b2-8778-2d02bcbbd7d3) ```py from xml.etree import cElementTree as ET ``` The "Use instead" section was also updated similarly. ## Test Plan N/A, no functionality/tests affected --- .../src/rules/pyupgrade/rules/deprecated_c_element_tree.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index ab1bd978f7..03dfec9322 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -14,12 +14,12 @@ use crate::{AlwaysFixableViolation, Edit, Fix}; /// /// ## Example /// ```python -/// from xml.etree import cElementTree +/// from xml.etree import cElementTree as ET /// ``` /// /// Use instead: /// ```python -/// from xml.etree import ElementTree +/// from xml.etree import ElementTree as ET /// ``` /// /// ## References