ITADN

Using named arguments would lost the signature of the method

#134OpenFarrukhw 创建于 2024-07-10
F
Farrukhwcommented
See the last call where arguments are given value by their names while changing their positions ```python from multipledispatch import dispatch @dispatch(int, int) def add(x, y): return x + y @dispatch(object, object) def add(x, y): return "%s + %s" % (x, y) @dispatch(object, object, object) def add(y, x , z): return f"{x} and {y} now {z}" print(add(3,4)) print(add('Me','You')) #using named arguments print(add(y='You', x='me')) ``` This would end up with the following errors: ```sh { "name": "NotImplementedError", "message": "Could not find signature for add: <>", "stack": "--------------------------------------------------------------------------- KeyError Traceback (most recent call last) File ~\\AppData\\Roaming\\Python\\Python311\\site-packages\\multipledispatch\\dispatcher.py:269, in Dispatcher.__call__(self, *args, **kwargs) 268 try: --> 269 func = self._cache[types] 270 except KeyError: KeyError: () During handling of the above exception, another exception occurred: NotImplementedError Traceback (most recent call last) Cell In[45], line 18 16 print(add('Me','You')) 17 #using named arguments ---> 18 print(add(y='You', x='me')) File ~\\AppData\\Roaming\\Python\\Python311\\site-packages\\multipledispatch\\dispatcher.py:273, in Dispatcher.__call__(self, *args, **kwargs) 271 func = self.dispatch(*types) 272 if not func: --> 273 raise NotImplementedError( 274 \"Could not find signature for %s: <%s>\" 275 % (self.name, str_signature(types)) 276 ) 277 self._cache[types] = func 278 try: NotImplementedError: Could not find signature for add: <>" } ```
0 条评论