Do not declare variable until necessary

This commit is contained in:
Andrew Murray 2024-01-27 19:26:55 +11:00
parent b81341ae7e
commit d2d9240de4

View File

@ -157,7 +157,6 @@ def grabclipboard():
raise NotImplementedError(msg)
p = subprocess.run(args, capture_output=True)
err = p.stderr
if p.returncode != 0:
allowed_errors = [
# wl-paste, when the clipboard is empty
@ -169,6 +168,7 @@ def grabclipboard():
# xclip, when the clipboard isn't initialized
b"There is no owner",
]
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'}"