For convenience, I wanted to subclass socket to create an ICMP socket:
class ICMPSocket(socket.socket): def __init__(self): socket.socket.__init__( self, socket.AF_INET, socket.SOCK_RAW, socket.getprotobyname("icmp")) def sendto(self, data, host): socket.socket.sendto(self, data, (host, 1))
However, I cannot override socket.sendto :
>>> s = icmp.ICMPSocket() >>> s.sendto <built-in method sendto of _socket.socket object at 0x100587f00>
This is because sendto is a "built-in method". According to the data model reference , this is “a really nice disguise of an inline function, this time containing an object passed to C as an implicit optional argument.”
My question is: is there a way to override inline methods when subclassing?
[Edit] Second question: if not, why not?
source share