Inspired by Greg Stein's proposed simplification of the _closesocket
class, I came up with an even simpler solution: raise the error in
__getattr__().
diff --git a/Lib/socket.py b/Lib/socket.py
index ce72b65..ec8d610 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -155,13 +155,9 @@
 
 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: