-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions will always return the first argument #115
Comments
Well, I have been thinking of deprecating In [1]: from varname import argname
...:
...: def fn(a, b):
...: print(argname("b"))
...:
...: x = 5
...: y = 42
...: fn(x, y)
y |
Well, I am fine with using Reproduce from varname import argname
def fn(*, b=1):
print(argname("b"))
a = 42
fn(b=a) # Error Stacktrace
|
@HeinrichAD I can't reproduce it with python3.12: 15:24:01 ❯ ipython
Python 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.26.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from varname import argname
...:
...: def fn(*, b=1):
...: print(argname("b"))
...:
...: a = 42
...: fn(b=a)
a Could you attach the environment you used (e.g. python version and varname version)? |
I do not know why, but it differs between What I did: virtualenv -p $(which python3.10) .venv
. .venv/bin/activate
pip install -U varname
python
>>> from varname import argname
>>> def fn(*, b=1):
... print(argname("b"))
...
>>> a = 42
>>> fn(b=a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in fn
File "/home/<user>/dev/test/python-varname-tests/.venv/lib/python3.10/site-packages/varname/core.py", line 451, in argname
raise VarnameRetrievingError(
varname.utils.VarnameRetrievingError: Cannot retrieve the node where the function is called. If I do the some command with pip install -U ipython
ipython
In [1]: from varname import argname
In [2]: def fn(*, b=1):
...: print(argname("b"))
...:
In [3]: a = 42
In [4]: fn(b=a)
a The problem is that if I run that in a normal script, I run it with |
See #107 |
Ok I see. Thank you. I will think about it, check it and come back to you later. (Most likely just to close this issue.) |
Since |
While looking for a fix for issue #114 I got the problem that only the first argument is evaluated. In other words inside a function it is always the first argument which will be returned.
Reproduce
Problem
It is quite difficult to identify the right point of failure, since there are multiple ways to approach this issue. I also do not know at the moment how this issue should be fixed. But the final moment where we get the wrong return is line 340:
python-varname/varname/core.py
Lines 333 to 340 in 1e07fce
out
contains all variables('x', 'y')
from the functionfn
(which should IMHO not be the case) and returns the first one sincenameof
is called with a single argument (no*more_vars
).Workaround
If possible, adjust the argument order.
The text was updated successfully, but these errors were encountered: