diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_annotations/shadowed_builtins.py b/crates/ruff_linter/resources/test/fixtures/flake8_annotations/shadowed_builtins.py
new file mode 100644
index 0000000000..c50f791bb1
--- /dev/null
+++ b/crates/ruff_linter/resources/test/fixtures/flake8_annotations/shadowed_builtins.py
@@ -0,0 +1,21 @@
+from collections import UserString as str
+from typing import override
+
+def foo():
+ return "!"
+
+def _foo():
+ return "!"
+
+class C:
+ @override
+ def __str__(self):
+ return "!"
+
+ @staticmethod
+ def foo():
+ return "!"
+
+ @classmethod
+ def bar(cls):
+ return "!"
diff --git a/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs b/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs
index adff541532..1d7047da77 100644
--- a/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs
+++ b/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs
@@ -142,23 +142,25 @@ impl AutoPythonType {
});
Some((expr, vec![no_return_edit]))
}
- AutoPythonType::Atom(python_type) => {
- let expr = type_expr(python_type)?;
- Some((expr, vec![]))
- }
+ AutoPythonType::Atom(python_type) => type_expr(python_type, checker, at),
AutoPythonType::Union(python_types) => {
if target_version >= PythonVersion::PY310 {
// Aggregate all the individual types (e.g., `int`, `float`).
+ let mut all_edits = Vec::new();
let names = python_types
.iter()
.sorted_unstable()
- .map(|python_type| type_expr(*python_type))
+ .map(|python_type| {
+ let (expr, mut edits) = type_expr(*python_type, checker, at)?;
+ all_edits.append(&mut edits);
+ Some(expr)
+ })
.collect::