From: Guido van Rossum Date: Tue, 18 Dec 2001 22:22:25 +0000 (+0000) Subject: Move the helper class _closedsocket *into* the _socketobject class. X-Git-Tag: v2.2.1c1~309 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99d2fbb8236dc792d7e3762cf1d7419405db4752;p=python Move the helper class _closedsocket *into* the _socketobject class. This way, when a socket object is deleted after the socket module has already been zapped by module shutdown, we don't get annoying warnings about exceptions in __del__ methods. --- diff --git a/Lib/socket.py b/Lib/socket.py index b45b4dc8e7..d2ac5932a2 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -129,11 +129,16 @@ _socketmethods = ( class _socketobject: + class _closedsocket: + def __getattr__(self, name): + raise error(9, 'Bad file descriptor') + def __init__(self, sock): self._sock = sock def close(self): - self._sock = _closedsocket() + # Avoid referencing globals here + self._sock = self.__class__._closedsocket() def __del__(self): self.close() @@ -153,12 +158,6 @@ class _socketobject: exec _s % (_m, _m) -class _closedsocket: - - def __getattr__(self, name): - raise error(9, 'Bad file descriptor') - - class _fileobject: def __init__(self, sock, mode, bufsize):