diff --git a/nameof.py b/nameof.py index 2df91cf..4873199 100644 --- a/nameof.py +++ b/nameof.py @@ -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 @@ -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.") \ No newline at end of file diff --git a/nameof_test.py b/nameof_test.py index 258533c..9f93725 100644 --- a/nameof_test.py +++ b/nameof_test.py @@ -1,3 +1,5 @@ +if True: + import os; os.environ["nameof_test"] = "True" from nameof import nameof import sys