Skip to content

bpo-42427: Use the errno attribute of OSError instead of args[0] #23449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Lib/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def readwrite(obj, flags):
if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
obj.handle_close()
except OSError as e:
if e.args[0] not in _DISCONNECTED:
if e.errno not in _DISCONNECTED:
obj.handle_error()
else:
obj.handle_close()
Expand Down Expand Up @@ -236,7 +236,7 @@ def __init__(self, sock=None, map=None):
try:
self.addr = sock.getpeername()
except OSError as err:
if err.args[0] in (ENOTCONN, EINVAL):
if err.errno in (ENOTCONN, EINVAL):
# To handle the case where we got an unconnected
# socket.
self.connected = False
Expand Down Expand Up @@ -346,7 +346,7 @@ def accept(self):
except TypeError:
return None
except OSError as why:
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
if why.errno in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
return None
else:
raise
Expand All @@ -358,9 +358,9 @@ def send(self, data):
result = self.socket.send(data)
return result
except OSError as why:
if why.args[0] == EWOULDBLOCK:
if why.errno == EWOULDBLOCK:
return 0
elif why.args[0] in _DISCONNECTED:
elif why.errno in _DISCONNECTED:
self.handle_close()
return 0
else:
Expand All @@ -378,7 +378,7 @@ def recv(self, buffer_size):
return data
except OSError as why:
# winsock sometimes raises ENOTCONN
if why.args[0] in _DISCONNECTED:
if why.errno in _DISCONNECTED:
self.handle_close()
return b''
else:
Expand All @@ -393,7 +393,7 @@ def close(self):
try:
self.socket.close()
except OSError as why:
if why.args[0] not in (ENOTCONN, EBADF):
if why.errno not in (ENOTCONN, EBADF):
raise

# log and log_info may be overridden to provide more sophisticated
Expand Down Expand Up @@ -557,7 +557,7 @@ def close_all(map=None, ignore_all=False):
try:
x.close()
except OSError as x:
if x.args[0] == EBADF:
if x.errno == EBADF:
pass
elif not ignore_all:
raise
Expand Down
2 changes: 1 addition & 1 deletion Lib/smtpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT,
# a race condition may occur if the other end is closing
# before we can get the peername
self.close()
if err.args[0] != errno.ENOTCONN:
if err.errno != errno.ENOTCONN:
raise
return
print('Peer:', repr(self.peer), file=DEBUGSTREAM)
Expand Down
4 changes: 2 additions & 2 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def readinto(self, b):
self._timeout_occurred = True
raise
except error as e:
if e.args[0] in _blocking_errnos:
if e.errno in _blocking_errnos:
return None
raise

Expand All @@ -722,7 +722,7 @@ def write(self, b):
return self._sock.send(b)
except error as e:
# XXX what about EINTR?
if e.args[0] in _blocking_errnos:
if e.errno in _blocking_errnos:
return None
raise

Expand Down