-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Summary
UP024 highlights specific aliased exceptions which might be removed in the future. When the except clause contains multiple exceptions, the error message can be a bit misleading. Simple Example:
try:
pass
except (IOError, ValueError):
passIn this example, IOError is an alias of OSError, that should be replaced, while ValueError is just a regular exception. Ruff correctly understands this (see uv tool run ruff@0.12.7 check --select UP024 --fix --diff), but its output does not distinguish between exceptions targeted by this rule and ones that aren't:
example.py:3:8: UP024 [*] Replace aliased errors with `OSError`
|
1 | try:
2 | pass
3 | except (ValueError, IOError):
| ^^^^^^^^^^^^^^^^^^^^^ UP024
4 | pass
|
= help: Replace with builtin `OSError`
The error message "Replace aliased errors with OSError" in connection with the highlighted section makes it seem as if both exceptions were aliases of OSError and should be replaced.
If this is possible, specifically highlighting the aliased exceptions would probably be sufficient to avoid this misinterpretation:
example.py:3:8: UP024 [*] Replace aliased errors with `OSError`
|
1 | try:
2 | pass
3 | except (ValueError, IOError):
| ^^^^^^^ UP024
4 | pass
|
= help: Replace with builtin `OSError`
Version
ruff 0.12.7 (c5ac998 2025-07-29)