Skip to content

Commit d58db49

Browse files
committed
refactor: replace IOError with OSError
<https://peps.python.org/pep-3151/>
1 parent 88fc4a4 commit d58db49

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

examples/when_ready.conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, server, max_mem):
1717
def memory_usage(self, pid):
1818
try:
1919
out = commands.getoutput("ps -o rss -p %s" % pid)
20-
except IOError:
20+
except OSError:
2121
return -1
2222
used_mem = sum(int(x) for x in out.split('\n')[1:])
2323
return used_mem

gunicorn/arbiter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def wakeup(self):
333333
"""
334334
try:
335335
os.write(self.PIPE[1], b'.')
336-
except IOError as e:
336+
except OSError as e:
337337
if e.errno not in [errno.EAGAIN, errno.EINTR]:
338338
raise
339339

gunicorn/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __call__(self, frame, event, arg):
3737
try:
3838
src = inspect.getsourcelines(frame)
3939
line = src[lineno]
40-
except IOError:
40+
except OSError:
4141
line = 'Unknown code named [%s]. VM instruction #%d' % (
4242
frame.f_code.co_name, frame.f_lasti)
4343
if self.trace_names is None or name in self.trace_names:

gunicorn/http/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ParseException(Exception):
1414
pass
1515

1616

17-
class NoMoreData(IOError):
17+
class NoMoreData(OSError):
1818
def __init__(self, buf=None):
1919
self.buf = buf
2020

@@ -82,15 +82,15 @@ def __str__(self):
8282
return "Unsupported transfer coding: %r" % self.hdr
8383

8484

85-
class InvalidChunkSize(IOError):
85+
class InvalidChunkSize(OSError):
8686
def __init__(self, data):
8787
self.data = data
8888

8989
def __str__(self):
9090
return "Invalid chunk size: %r" % self.data
9191

9292

93-
class ChunkMissingTerminator(IOError):
93+
class ChunkMissingTerminator(OSError):
9494
def __init__(self, term):
9595
self.term = term
9696

gunicorn/pidfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def validate(self):
8080
if e.args[0] == errno.ESRCH:
8181
return
8282
raise
83-
except IOError as e:
83+
except OSError as e:
8484
if e.args[0] == errno.ENOENT:
8585
return
8686
raise

gunicorn/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def check_is_writable(path):
566566
try:
567567
with open(path, 'a') as f:
568568
f.close()
569-
except IOError as e:
569+
except OSError as e:
570570
raise RuntimeError("Error: '%s' isn't writable [%r]" % (path, e))
571571

572572

@@ -587,7 +587,7 @@ def has_fileno(obj):
587587
# check BytesIO case and maybe others
588588
try:
589589
obj.fileno()
590-
except (AttributeError, IOError, io.UnsupportedOperation):
590+
except (AttributeError, OSError, io.UnsupportedOperation):
591591
return False
592592

593593
return True

tests/test_pidfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def builtin(name):
1616
@mock.patch(builtin('open'), new_callable=mock.mock_open)
1717
def test_validate_no_file(_open):
1818
pidfile = gunicorn.pidfile.Pidfile('test.pid')
19-
_open.side_effect = IOError(errno.ENOENT)
19+
_open.side_effect = OSError(errno.ENOENT)
2020
assert pidfile.validate() is None
2121

2222

0 commit comments

Comments
 (0)