Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions nameof.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import ast
from typing import Any

import os

def nameof(var: Any):
# Try to extract the argument expression from the caller's source code
Expand All @@ -27,6 +27,7 @@ def nameof(var: Any):
return arg.attr

except Exception as e:
print(e)
if os.environ.get("nameof_test") or os.environ.get("nameof_test_debug"):
print("Error in nameof function:", e)

raise ValueError("Could not determine variable name. Ensure the variable is defined in the caller's scope.")
2 changes: 2 additions & 0 deletions nameof_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if True:
import os; os.environ["nameof_test"] = "True"
from nameof import nameof
import sys

Expand Down