Skip to content

nameof not working inside of for loop #5

@tbrodbeck

Description

@tbrodbeck

If I run this code the first call on a variable can be processed. But if I call it inside a for loop I get an error.

import varname
test = {}
print(varname.nameof(test))
for i in [0]:
  print(varname.nameof(test))
test
---------------------------------------------------------------------------
VarnameRetrievingError                    Traceback (most recent call last)
<ipython-input-39-f74218a72604> in <module>
      2 print(varname.nameof(test))
      3 for i in [0]:
----> 4   print(varname.nameof(test))

~/dev/textSum/.direnv/python-3.8.3/lib/python3.8/site-packages/varname.py in nameof(*args)
    183     if not exec_obj.node:
    184         # we cannot do: assert nameof(a) == 'a' in pytest
--> 185         raise VarnameRetrievingError("Callee's node cannot be detected.")
    186 
    187     assert isinstance(exec_obj.node, ast.Call)

VarnameRetrievingError: Callee's node cannot be detected.

Tested on macOS Catalina with python 3.8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions