Treat os.error as an OSError alias (#7582)

Closes https://github.com/astral-sh/ruff/issues/7580.
This commit is contained in:
Charlie Marsh 2023-09-21 17:18:14 -04:00 committed by GitHub
parent 74dbd871f8
commit a51b0b02f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View file

@ -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

View file

@ -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"]
)
})
}

View file

@ -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