Skip to content

Commit

Permalink
Treat os.error as an OSError alias (#7582)
Browse files Browse the repository at this point in the history
Closes #7580.
  • Loading branch information
charliermarsh authored Sep 21, 2023
1 parent 74dbd87 commit a51b0b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit a51b0b0

Please sign in to comment.