alexmojaki / nameof

Python function to get the name of a variable or attribute, as in C#
MIT License
17 stars 2 forks source link

Broken in Python 3.12 #2

Open LinqLover opened 1 month ago

LinqLover commented 1 month ago
Python 3.12.7 (main, Oct  1 2024, 08:52:12) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nameof
>>> nameof.nameof(nameof)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/christoph/.local/lib/python3.12/site-packages/nameof.py", line 8, in nameof
    return _nameof(frame.f_code, frame.f_lasti)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christoph/.local/lib/python3.12/site-packages/nameof.py", line 14, in _nameof
    (current_instruction_index, current_instruction), = (
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 1, got 0)

In Python 3.10, it still worked. Any chance to get this fixed again? :)

alexmojaki commented 1 month ago

I should probably archive this project and recommend not using it, I hacked it together quickly for fun and don't want to maintain it. I suggest https://github.com/pwwang/python-varname?tab=readme-ov-file#getting-variable-names-directly-using-nameof, I contributed to it and it's more reliable.

LinqLover commented 4 weeks ago

That's good to know! If you think that makes sense and it supports everything of nameof, deprecating nameof sounds like a good idea. Otherwise (or even in this case), I would not complain if you could merge my PR :)