Skip to content

Exploration of supporting single-dispatched functions for argname() #53

Closed
@pwwang

Description

@pwwang
>>> from varname import argname
>>> from functools import singledispatch
>>> 
>>> @singledispatch
... def add(a, b):
...     ...
... 
>>> @add.register(int)
... def _(a, b):
...     aname = argname(a, b)
...     print(aname)
...     return a + b 
... 
>>> def mul(a, b):
...     aname = argname(a, b)
...     print(aname)
...     return a * b
... 
>>> x = y = 1
>>> 
>>> mul(x, y)
('x', 'y')
1
>>> 
>>> add(x, y)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    add(x, y)
  File "/.../lib/python3.7/functools.py", line 840, in wrappe
r
    return dispatch(args[0].__class__)(*args, **kw)
  File "<input>", line 3, in _
    aname = argname(a, b)
  File "/.../varname/core.py", line 401, in argnam
e
    f"No value passed for argument {argnode.id!r}, "
ValueError: No value passed for argument 'a', or it is not an argument at all.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions