Skip to content
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

Errors on Python 3.9.7 #76

Closed
robertsdotpm opened this issue May 20, 2022 · 3 comments
Closed

Errors on Python 3.9.7 #76

robertsdotpm opened this issue May 20, 2022 · 3 comments
Labels

Comments

@robertsdotpm
Copy link

robertsdotpm commented May 20, 2022

Hello, I'm trying to use this package on Python 3.9.7 (very recent I know) and the sample code throws errors. Here are the results:

>>> xxxxx = varname()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.local/lib/python3.9/site-packages/varname/core.py", line 103, in varname
    refnode = get_node(frame + 1, ignore, raise_exc=raise_exc)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/varname/utils.py", line 127, in get_node
    return get_node_by_frame(frameobj, raise_exc)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/varname/utils.py", line 132, in get_node_by_frame
    exect = Source.executing(frame)
  File "/home/ubuntu/.local/lib/python3.9/site-packages/executing/executing.py", line 309, in executing
    lineno = frame.f_lineno
AttributeError: 'NoneType' object has no attribute 'f_lineno'

Then I also tried the following and got a different error:

>>> def function():
...     return varname()
... 
>>> xxx = function()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in function
  File "/home/ubuntu/.local/lib/python3.9/site-packages/varname/core.py", line 106, in varname
    raise VarnameRetrievingError("Unable to retrieve the ast node.")
varname.utils.VarnameRetrievingError: Unable to retrieve the ast node.

I think the idea behind the module though is a very good idea. Don't let it discourage you that there seems to be problems on the most recent versions of Python. This is a cool and useful hack. If you can get it working let me know! I have an elegant use-case in my state machine code.

@pwwang
Copy link
Owner

pwwang commented May 20, 2022

Could you reveal the environment running your code? Such as raw python REPL, ipython, jupyter notebook or as a python script?

And I would not agree that

there seems to be problems on the most recent versions of Python.

based on the CI results: https://github.com/pwwang/python-varname/actions/runs/2001581362

@robertsdotpm
Copy link
Author

@pwwang thanks for such a fast reply!

I tried the code out just in a Python interactive shell with python3 on Ubuntu 21.10 x86_64.

@pwwang pwwang added the REPL label May 20, 2022
@robertsdotpm
Copy link
Author

robertsdotpm commented May 20, 2022

@pwwang Just tried it without the shell. It works fine. Thanks! Will use this in my code after-all.

Edit: Maybe it would make sense to add a prominent warning that it doesn't work in the shell or something on the project and pypy page? Cheers man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants