On Thu, Aug 6, 2020 at 11:11 AM Steven D'Aprano
[Dominik Vilsmeier]:
That should be possible by doing `fred = my_property(42)` and defining `__set_name__` on the `my_property` class.
Just because you define your own dunder method (which you shouldn't do, since dunders are reserved for the interpreter's use) doesn't make something which is a syntax error stop being a syntax error.
This isn't "defining your own dunder". The syntax as described already works inside a class: class my_property: def __init__(self, n): self.n = n def __set_name__(self, cls, name): print("I'm a property %r on class %s" % (name, cls.__name__)) class X: fred = my_property(42) I'm a property 'fred' on class X But AIUI this is implemented by type.__new__, so there's no useful way to extend this to globals and/or locals. ChrisA