mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-20 23:44:59 +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:
@@ -8,6 +8,7 @@ import sys
|
||||
from base64 import standard_b64encode
|
||||
from collections import defaultdict, deque
|
||||
from itertools import count
|
||||
from contextlib import suppress
|
||||
|
||||
from kitty.utils import fit_image
|
||||
|
||||
@@ -172,10 +173,8 @@ class ImageManager:
|
||||
if in_flight:
|
||||
pl = in_flight.popleft()
|
||||
if payload.startswith('ENOENT:'):
|
||||
try:
|
||||
with suppress(Exception):
|
||||
self.resend_image(image_id, pl)
|
||||
except Exception:
|
||||
pass
|
||||
if not in_flight:
|
||||
self.placements_in_flight.pop(image_id, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user