diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP024_0.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP024_0.py index 523ee451f9eda..9c882303e9bc2 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP024_0.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP024_0.py @@ -104,3 +104,12 @@ def get_owner_id_from_mac_address(): mac_address = get_primary_mac_address() except(IOError, OSError) as ex: msg = 'Unable to query URL to get Owner ID: {u}\n{e}'.format(u=owner_id_url, e=ex) + + +# Regression test for: https://github.com/astral-sh/ruff/issues/7580 +import os + +try: + pass +except os.error: + pass diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs index 45510ccfc1fa0..c3da16ca5ed6f 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs @@ -61,7 +61,7 @@ fn is_alias(expr: &Expr, semantic: &SemanticModel) -> bool { matches!( call_path.as_slice(), ["", "EnvironmentError" | "IOError" | "WindowsError"] - | ["mmap" | "select" | "socket", "error"] + | ["mmap" | "select" | "socket" | "os", "error"] ) }) } diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP024_0.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP024_0.py.snap index 7ceec856fe07e..da339bd9bbab1 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP024_0.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP024_0.py.snap @@ -281,5 +281,25 @@ UP024_0.py:105:11: UP024 [*] Replace aliased errors with `OSError` 105 |- except(IOError, OSError) as ex: 105 |+ except OSError as ex: 106 106 | msg = 'Unable to query URL to get Owner ID: {u}\n{e}'.format(u=owner_id_url, e=ex) +107 107 | +108 108 | + +UP024_0.py:114:8: UP024 [*] Replace aliased errors with `OSError` + | +112 | try: +113 | pass +114 | except os.error: + | ^^^^^^^^ UP024 +115 | pass + | + = help: Replace `os.error` with builtin `OSError` + +ℹ Fix +111 111 | +112 112 | try: +113 113 | pass +114 |-except os.error: + 114 |+except OSError: +115 115 | pass