Dark magics about variable names in python
Overall
score
90%
A utility that enables objects to automatically capture and store the variable name they're assigned to during instantiation.
config stores "config" as the object's name @testdatabase_connection stores "database_connection" as the object's name @testobj.setting, it captures "setting" as its name @testregistry['handler'], it captures "handler" as its name @test@generates
class NamedObject:
"""
A class that automatically captures the variable name it's assigned to.
Instances store their assigned variable name in a `name` attribute.
"""
def __init__(self):
"""Initialize a NamedObject and capture the assignment variable name."""
pass
@property
def name(self) -> str:
"""Return the captured variable name."""
passProvides variable name introspection capabilities.
Install with Tessl CLI
npx tessl i tessl/pypi-varnameevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10