Alex Hall wrote:
This sounds a lot like this suggestion to add a nameof function/operator: https://firstname.lastname@example.org/thread/UUFFAI3...
Indeed, it sounds like the `nameof` operator; I had not heard of this suggestion before your message. However, there is at least two important differences between both suggestions which may matter:
- `nameof` should be implemented as a new operator with a dedicated implementation using AST and raising SyntaxError; `__attrs__` is simpler and dynamic (pythonic?), just a `type` object attribute, and cannot fail. (I don't mention implementation using CPython `current_frame` specificity, as it is unavailable in Pypy, IronPython, etc.) - `nameof` is only about variable/attribute name; `__attrs__` has a dual use: attribute name and `getattr` typing (i don't see how the second could be considered with `nameof`)