Skip to content

os-error-alias

Pythonstyleno fixdefault: offpython/ruff

Reports EnvironmentError, IOError, WindowsError, mmap.error, os.error, select.error or socket.error in an except clause or a raise.

Since Python 3.3 these names are other names of OSError. Using the old ones makes a reader look for a difference that is not there.

To fix, write OSError.

Reported
...
try:
pass
except IOError:
pass
except (EnvironmentError, ValueError, socket.error):
pass
except select.error:
pass
raise IOError("x")
...
python:
lint:
rules:
os-error-alias: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line os-error-alias in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff UP024 full