Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat os.error as an OSError alias #7582

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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