Inspired by Greg Stein's proposed simplification of the _closesocket
authorGuido van Rossum <guido@python.org>
Sat, 18 Aug 2001 21:00:39 +0000 (21:00 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 18 Aug 2001 21:00:39 +0000 (21:00 +0000)
class, I came up with an even simpler solution: raise the error in
__getattr__().

Lib/socket.py

index ce72b65c6e4c3f788a0df0ba0a5db7bd138b372c..ec8d61092b93892102286c2bc3188f67887cbd73 100644 (file)
@@ -155,13 +155,9 @@ class _socketobject:
 
 class _closedsocket:
 
-    def _bummer(self):
+    def __getattr__(self, name):
         raise error(9, 'Bad file descriptor')
 
-    _s = "def %s(self, *args): self._bummer()\n\n"
-    for _m in _socketmethods:
-        exec _s % _m
-
 
 class _fileobject: