mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Use "with suppress()" to suppress python exceptions
Using
```Python
with suppress(OSError):
os.remove('somefile.tmp')
```
instead of
```Python
try:
os.remove('somefile.tmp')
except OSError:
pass
```
makes the code more compact and more readable IMO.
This pattern was recommended by Raymond Hettinger, a Python Core
Developer in his talk "Transforming Code into Beautiful, Idiomatic Python" at https://www.youtube.com/watch?v=OSGv2VnC0go. The transcript is available at https://github.com/JeffPaine/beautiful_idiomatic_python
This commit is contained in:
@@ -15,6 +15,7 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from contextlib import suppress
|
||||
|
||||
import requests
|
||||
|
||||
@@ -112,10 +113,8 @@ def run_sdist(args):
|
||||
shutil.copytree(os.path.join(docs_dir, '_build', x), os.path.join(dest, x))
|
||||
dest = os.path.abspath(os.path.join('build', f'kitty-{version}.tar'))
|
||||
subprocess.check_call(['tar', '-cf', dest, os.path.basename(base)], cwd=tdir)
|
||||
try:
|
||||
with suppress(FileNotFoundError):
|
||||
os.remove(dest + '.xz')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
subprocess.check_call(['xz', '-9', dest])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user