Skip to content

subprocess-run-without-check (PLW1510)

Added in v0.0.285 · Related issues · View source

Derived from the Pylint linter.

Fix is sometimes available.

What it does

Checks for uses of subprocess.run without an explicit check argument.

Why is this bad?

By default, subprocess.run does not check the return code of the process it runs. This can lead to silent failures.

Instead, consider using check=True to raise an exception if the process fails, or set check=False explicitly to mark the behavior as intentional.

Example

import subprocess

subprocess.run(["ls", "nonexistent"])  # No exception raised.

Use instead:

import subprocess

subprocess.run(["ls", "nonexistent"], check=True)  # Raises exception.

Or:

import subprocess

subprocess.run(["ls", "nonexistent"], check=False)  # Explicitly no check.

Fix safety

This rule's fix is marked as display-only because it's not clear whether the potential exception was meant to be ignored by setting check=False or if the author simply forgot to include check=True. The fix adds check=False, making the existing behavior explicit but possibly masking the original intention.

References