
On 2020-02-09 9:44 a.m., Eric V. Smith wrote:
On 2/9/2020 7:34 AM, Soni L. wrote:
I propose that:
def foo(print(x)): pass
becomes:
def foo(x): x = print(x) pass
or, alternatively we could have decorators in function args:
def foo(@print x): pass
which would probably be more aligned with the rest of python actually.
anyway, this would be nice I think. I could really use it.
I'm having a hard time imagining where this would be useful. Could you give a concrete example where it would make some code clearer? Surely you wouldn't use it with print(), which returns None.
Of course not. It'd be useful with traits. Turn this: from traitobject import Trait, TraitObject, impl class MyTrait(Trait): def x(self): raise NotImplementedError class MyClass(TraitObject): @impl(MyTrait) class MyTrait: def x(self): print("Hello,") self.x() def x(self): print("World!") def my_fn(x): x = MyTrait(x) x.x() my_fn(MyClass()) into this: from traitobject import Trait, TraitObject, impl class MyTrait(Trait): def x(self): raise NotImplementedError class MyClass(TraitObject): @impl(MyTrait) class MyTrait: def x(self): print("Hello,") self.x() def x(self): print("World!") def my_fn(@MyTrait x): x.x() my_fn(MyClass()) (this may not be "real code" but it's one of the test cases in my trait lib project)
Eric _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VGIQ35... Code of Conduct: http://python.org/psf/codeofconduct/