Skip to content

Commit

Permalink
Do not declare variable until necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 27, 2024
1 parent 20c9043 commit 60a8cc1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ def grabclipboard():
raise NotImplementedError(msg)

p = subprocess.run(args, capture_output=True)
err = p.stderr
if p.returncode != 0:
allowed_errors = [
b"Nothing is copied", # wl-paste, when the clipboard is empty
b"not available", # wl-paste/debian xclip, when an image isn't available
b"cannot convert", # xclip, when an image isn't available
b"There is no owner", # xclip, when the clipboard isn't initialized
]
err = p.stderr
if any(e in err for e in allowed_errors):
return None
msg = f"{args[0]} error: {err.strip().decode() if err else 'Unknown error'}"
Expand Down

0 comments on commit 60a8cc1

Please sign in to comment.