44import re
55import time
66from pythonosc import osc_packet
7+ from typing import overload
8+ from types import FunctionType
79
810class Handler (object ):
911 def __init__ (self , _callback , _args , _needs_reply_address = False ):
@@ -58,7 +60,18 @@ def map(self, address, handler, *args, needs_reply_address=False):
5860 self ._map [address ].append (handlerobj )
5961 return handlerobj
6062
61- def unmap (self , address , handler , * args , needs_reply_address = False ):
63+ @overload
64+ def unmap (self , address : str , handler : Handler ):
65+ """Remove an already mapped handler from an address
66+
67+ Args:
68+ - address: An explicit endpoint.
69+ - handler: A Handler object as returned from map().
70+ """
71+ pass
72+
73+ @overload
74+ def unmap (self , address : str , handler : FunctionType , * args , needs_reply_address : bool = False ):
6275 """Remove an already mapped handler from an address
6376
6477 Args:
@@ -68,8 +81,15 @@ def unmap(self, address, handler, *args, needs_reply_address=False):
6881 - args: Any additional arguments that will be always passed to the
6982 handlers after the osc messages arguments if any.
7083 - needs_reply_address: True if the handler function needs the
71- originating client address passed (as the first argument)."""
72- self ._map [address ].remove (Handler (handler , list (args ), needs_reply_address ))
84+ originating client address passed (as the first argument).
85+ """
86+ pass
87+
88+ def unmap (self , address , handler , * args , needs_reply_address = False ):
89+ if isinstance (handler , Handler ):
90+ self ._map [address ].remove (handler )
91+ else :
92+ self ._map [address ].remove (Handler (handler , list (args ), needs_reply_address ))
7393
7494 def handlers_for_address (self , address_pattern ):
7595 """yields Handler namedtuples matching the given OSC pattern."""
0 commit comments